??xml version="1.0" encoding="utf-8" standalone="yes"?>
一个游戏引擎原型基本蛋生了Q我们命名它?RedLightQ它基本实现?br>
(0) Win32E序渲染框架
(1) UI的基本消息交互流E,XMLH体配置理QUI皮肤配置理Q基本的UI控g库,多分辩率无缝UI拼图
(2) 室外场景理
(3) 摄相\径摄?br>(4) 3D Max8模型及骨骼动d出插?br>(5) 模型渲染, 关键帧动d骨骼动画控制
(6) 基本的水面反效?br>(7) 单的面粒子系l?br>(8) 声音控制接口
q是一个单机游戏引擎的原型Q功能有限,但它ȝ不i使命完成了一个项目了Q以后再扩展使它日益强大吧!
]]>
]]>
(一)、正交投影时QOpenGL以屏q左上角?0,0), 而D3D却以屏幕中心?0,0)
(?、OpenGL使用x坐标p, 而D3D使用左手坐标p?br>(?、OpenGL使用旋{操作{{入的角度参数?角度, 而D3D?弧度Q所以注意要PI * Angle / 180
下面我把具体地API对照关系列出?不是很全Q以后添加中.......)
1. 坐标变换
pos = D3DXVECTOR3(0,2,-1.5);
at = D3DXVECTOR3(0,0,0);
up = D3DXVECTOR3(0,1,0);
D3DXMatrixLookAtLH(&view,&pos,&at,&up);
pd3dDevice->SetTransform(D3DTS_VIEW,&view);
2. l制
pd3dDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
DrawPrimitive()
DrawIndexedPrimitive()
DrawPrimitiveUP()
DrawIndexedPrimitiveUP()
3. 颜色
4. 片段试
(1) 深度试
g_pDevice->SetRenderState(D3DRS_ZENABLE, TRUE); //glEnable(GL_DEPTH_TEST);
g_pDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL); //glDepthFunc(GL_LEQUAL);
//--------------------------------------------------------------------------------------------------------
g_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); //glEnable(GL_CULL_FACE);
(2) Alpha试
//--------------------------------------------------------------------------------------------------------
g_pDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); //glEnable(GL_ALPHA_TEST);
g_pDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); //glAlphaFunc(GL_GREATER, 0.1f);
g_pDevice->SetRenderState(D3DRS_ALPHAREF, 0.1 * 255); //取D?0 ~ 255
(3) 剪裁试 (q面剪切)
//--------------------------------------------------------------------------------------------------------
// Enable clip plane for reflection map
CMatrix44f pWorldViewProjIT=m_pWorldViewProj;
//pWorldViewProjIT.Transpose();
pWorldViewProjIT.Invert();
// Transform plane to clip-space
float pClipSpacePlane[4];
float pClipPlane[]= { 0, 0, 1, 0};
// Check if camera is below water surface, if so invert clip plane
CVector3f pEye=(CVector3f)m_pCamera.GetPosition();
if(-pEye.m_fZ<0.0)
{
pClipPlane[2]=-pClipPlane[2];
}
MatrixTransformPlane(pClipSpacePlane, pClipPlane, pWorldViewProjIT);
// enable clip plane now
g_pDevice->SetClipPlane(0, pClipSpacePlane);
g_pDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 1);
(4) 模板试
//--------------------------------------------------------------------------------------------------------
g_pDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE);
g_pDevice->SetRenderState(D3DRS_STENCILFUNC, 3DCMP_ALWAYS);
g_pDevice->SetRenderState(D3DRS_STENCILREF, 0x1); //取D?0 ~ 255
Device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
5. U理操作
g_pDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
g_pDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
g_pDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
g_pDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
g_pDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
6. ~冲区操?br>
(1) 颜色~冲
//--------------------------------------------------------------------------------------------------------
g_pDevice->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
g_pDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0x000000F);
(2) 深度~冲
//--------------------------------------------------------------------------------------------------------
g_pDevice->SetRenderState(D3DRS_ZENABLE, TRUE); //glEnable(GL_DEPTH_TEST);
g_pDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); //glDepthMask(GL_TRUE);
(3) 模板~冲
//--------------------------------------------------------------------------------------------------------
(4) 渲染到纹?br> //--------------------------------------------------------------------------------------------------------
// Render targets
IDirect3DSurface9 *m_plD3DBackbufferSurf,
*m_plD3DDepthStencilSurfAA,
*m_plD3DDepthStencilSurf;
CRenderTarget *m_pRTRefraction, *m_pRTReflection; //(自定义纹理类)
//-----------------------------------------------------------------------------------
// Get backbuffer
g_pDevice->GetRenderTarget(0, &m_plD3DBackbufferSurf);
// Get depthstencil
g_pDevice->GetDepthStencilSurface(&m_plD3DDepthStencilSurfAA);
// Restore previous states
g_pDevice->SetRenderTarget(0, m_plD3DBackbufferSurf);
g_pDevice->SetDepthStencilSurface(m_plD3DDepthStencilSurfAA);
// (1)折射?-------------------------------------------------------------------------
//下面的语句调用了 g_pDevice->CreateRenderTarget(iWidth, iHeight, (D3DFORMAT) iFormat, (D3DMULTISAMPLE_TYPE)iAASamples, 0, 0, &m_plD3Surf, 0));
if(FAILED(m_pRTRefraction->Create(m_fWidth>>1, m_fHeight>>1, D3DFMT_A8R8G8B8)))
{
return APP_ERR_INITFAIL;
}
// Create depthstencil withouth multisampling
g_pDevice->CreateDepthStencilSurface(m_fWidth, m_fHeight, D3DFMT_D24X8, (D3DMULTISAMPLE_TYPE)0, 0, 0, &m_plD3DDepthStencilSurf, 0);
g_pDevice->SetRenderTarget(0, m_pRTReflection->GetSurface());
g_pDevice->StretchRect(m_plD3DBackbufferSurf, 0, m_pRTRefraction->GetSurface(), 0, D3DTEXF_NONE);
// (2)反射?----------------------------------------------------------------------------------
m_pRTReflection=new CRenderTarget;
if(FAILED(m_pRTReflection->Create(m_fWidth>>2, m_fHeight>>2, D3DFMT_A8R8G8B8)))
{
return APP_ERR_INITFAIL;
}
g_pDevice->SetRenderTarget(0, m_pRTReflection->GetSurface());
//-----------------------------------------------------------------------------------
g_pDevice->SetRenderTarget(0, m_pRTReflection->GetSurface());
g_pDevice->SetDepthStencilSurface(m_plD3DDepthStencilSurf);
g_pDevice->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(255, 0, 0, 128), 1.0f, 0);
SetViewport(m_pRTReflection->GetWidth(), m_pRTReflection->GetHeight());
//-----------------------------------------------------------------------------------
D3DXSaveTextureToFile("imageTex.jpg",D3DXIFF_JPG,(IDirect3DTexture9*)m_pWavesBump->GetTexture(),NULL);
7. 混合操作
g_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); //glDisable(GL_BLEND);
g_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
g_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
8. 灯光与材?br> g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE); //glDisable(GL_LIGHTING);
D3DMATERIAL9 mtrl;
mtrl.Ambient = a;
mtrl.Diffuse = d;
mtrl.Specular = s;
mtrl.Emissive = e;
mtrl.Power = p;
Device->SetMaterial(&mtrl); //在设|纹理前讑֮
//讄当前使用的纹?br>
//Direct3D 9.0 SDK 开发参考Direct3D 9.0 SDK 文档 (中文?
词汇?
DirectX 8 教程
你也可以?COM 对象想象成一套ؓ某个主题而设计的一整套库函数。DX 提供了一套完整的设计3D游戏的库?
http://baike.baidu.com/view/1169027.htm
使用DirectX的不同组Ӟ你需要链接不同的静态库。例如你要用DirectDrawlgQ你需要ddraw.lib?
对于DirectDrawQ这个头文g是ddraw.h?/com~程
D3D.H
http://wowe1314.blog.163.com/blog/static/2358876200751191213583/
在Direct3D~程中,我们要做的工作基本上可以归纳为:
调用适当的函数获取接口指针;
调用接口的方法(成员函数Q来完成所需功能Q?
用完接口后,调用ReleaseҎq行“释放”Q注意释N序应该和获取它们的顺序相反?
http://www.lihuasoft.net/article/show.php?id=2928
Microsoft_DirectX_9.0c里的 9个DirectX的DLL
DX9和DX10在渲染流水线上都是有天壤之别的,好在DX高版本开发包q行库中包含了对低版本开发包q行库的实现Q所以用DX8开发的E序QDX9q行库也能够很好的支持,在安装有D9q行库的pȝ上跑DX8开发的E序不需要再安装DX8q行库,但是q个兼容性支持在最q被微Y逐渐攑ּQ有时候DX9的不同更新版本做的程序也不能向下兼容Q比如DX9FEB2007SDK,同DX9AUG2006SDK在shader~译规则上也是不同的Q?007攑ּ了VS2.0和PS2.0以下版本shader的支持,同时对于HLSL?include相对路径引用的默认根目录也是有区别的.openGL的shader扩展不同的厂商有不同的扩展开发包Q但是这U情况随着GLSL和openGL2.0的出现有所改观.同时OpenGL是跨q_的而DX不是Q这意味着用OpenGL和GNU C++规则开发的E序可以同时在Linux,unix和安装有GNU环境的Windows上同时运行。从效率上来看,DX׃数据时批量写入显存的Q同OpenGL的单条函数写入来讲DX效率上要高一些,不过q来OpenGL也支持了批写入,只是支持批写入的OpenGL攑ּ了openGL一惯的优势也就是语a架构上的z得函数的数目变得很冗杂。在效果上看DX9同支持GLSL或CG扩展的openGL可以实现相同的显C效果。但是有一点不同是DXUT和D3DX在一些基l制上比glu和openGL ARB Extend要差一点,比如l制虚线QDX没有好的函数可以是实现这一功能。但是DX的扩展工hopenGL扩展工具又有多余的优势比如向量计?GUI控g,mesh优化和曲面展开QPRT预计等{和性能试{等上又要强一炏VDX10同OpenGL比较感觉openGL不是同一个数量上的产品QDX10在渲染流水线和架构上和能够实现的效果上要比DX9和openGLq步的多。要做面向未来的游戏产品量q是用DX10吧?
LPDIRECT3D9 D3DL?
LPDIRECT3DDEVICE9 D3DgL?
LPDZRECT3DVERTXBUFFER9 点~冲区接?
LPD3DVIEWPORT9 视口接口
LPD3DDISPLAYMODE D3D讑֤昄模式接口
LPD3DPRESENT_PARAMETERS 创徏l构用来保存讑֤的显C模式接?
LPD3DXVECTOR3 3D向量接口
LPDIRECT3DTEXTURE9 U理接口
ID3DXSprite _接口
g.pvb 成员函数
g_pD3D 成员函数
g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm) 获取昄模式
g_pd3dDevice 成员函数
g_pd3dDevice->SetRenderStateQ,BOOLQ?是否开启灯?
g_pd3dDevice->SetTransform( D3DTS_WORLD, &(matWorld * matWorld_x));//上面计出来的旋{矩阵Q设|ؓ世界变换矩阵
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );写入?
g_pd3dDevice->SetFVF() 讄FVF
g_pd3dDevice->DrawIndexedPrimitive( dŞ? 0, 0, 点个? 0, 三角形个?); ?
timeGetTime 当前pȝ的时?
DIRECT3DTXTURE 文理接口
BITMAPPEILEHEADER 文g?
BITMAPINFOHEADER 信息?
fread M个数据块
biBitcout 每个象素占几个字?
bicompression 是否被压~?
fseek 跻I偏移指针
greatetxture 创徏一个空文理
D3Dcaked_RECT 锁定l构?
setTexturestagestata 讄文理操作
CONSTD3DMATRIX* q行变换的变换矩?
l构?
D3DPRESENT_PARAMETERS 存储D3D讑֤信息
D3DXMATRIX 修改矩阵
数组
CUSTOMVERTEX 讄点位置颜色信息
矩阵函数
D3DXMATRIX * D3DXMatrixIdentityQPOut,pMQ?单位矩阵
D3DXMATRIX * D3DXMatrixTransposeQ上Q?nbsp; 矩阵转置
D3DXMATRIX * D3DXMatrixInverseQ上中间加个FLOATQ?逆矩?
D3DXMATRIX * D3DXMatrixTransformationQ)
D3DXMATRIX* D3DXMatrixTranslationQ输出矩阵,XQYQZQ?q移变换
D3DXMATRIX * D3DXMatrixScalingQ上Q?~放变换
FLOAT D3DXPlaneDotCoordQpp,pvQ?点和q面之见的关p?
D3DXPLANE * D3DXPlaneFromPointNormalQPOUTQPPOINTQPNORMALQ?构造子
D3DXPLANE * D3DXPlaneFromPoints(Pout,pv1,pv2,pv3) 通过Ҏ描述q面
D3DXPLANE * D3DPlaneNormalize(POUT,PP) 标准化一个^?
D3DXPLANE * D3DXPlaneTransform(POUT,PP,PM) q移q面
D3DXM
转换函数
D3DXMATRIX* D3DXMatrixLookAtLH(输出用于视图转换的矩阵,摄象机的位置Q摄象机面向的位|,摄象机的正方? 视图转换的矩?
D3DXMATRIX* D3DXMatrixOrthoLH(输出用于正交投媄的交换矩阵,取景宽,取景高,取景L象机的最q距,取景L象机的最q距? 正交投媄变换矩阵
D3DXMATRIX* D3DXMatrixPerspectiveFovLH(输出用于透视投媄的交换矩阵,摄象机镜头的夹角YQ^截台体的U|比,q^截面的距,q^截面的距? 透视投媄的矩?
Direct3DCreate9(D3D版本) 创徏D3D对象
讑֤函数
SetTransform(变换的类型,变换的变换矩? 讄左手或右手坐?
SetViewport(视口指针) 讄q近距离
GetClientRect(hWnd,*RECT) 获取H口l图区域
memcpyQ指针,数组Q长度) 拯
SetStreamSource(0,G.pvb接口指针Q?,长度) 数据?
GetAdapterDisplayMode(指定昄卡序列号Q存储显C模式的指针) 获取昑֍的模?
HRESULT CreateDevice(昑֍序列PD3D讑֤cdQ所属窗口句柄,D3Dq行3Dq算Q存储D3D讑֤相关信息指针Q返回D3D讑֤借口指针的地址) 创徏讑֤借口
HRESULT CreateVertexBuffer(点~冲区大(字节Q,点~冲区属性,灉|点格式Q顶点缓冲区内存位置Q顶点缓冲区指针地址Q保留参数通常?) 创徏点~冲
HRESULT CreateIndexBuffer(索引~冲区大(字节Q?点~冲区属?FMT颜色,点~冲区内存位|?索引~冲区指针地址Q保留参数通常?) 创徏索引~冲
HRESULT Lock(加锁内存起始地址Q加锁内存大,q回内存指针地址Q加锁属? 加羃内存
HRESULT UnLock() 解锁
HRESULT SetStreamSource(渲染数据序列号Q进行绑定连接的点~冲区指针,q行l定q接渲染数据的起始位置Q渲染数据流中一个顶Ҏ占的内存大小) 点~冲区和渲染数据连?
HRESULT SetFVF(灉|点格式) 讄点格式
HRESULT DrawPrimitive(l制的图元类型,l制的开始顶点的索引|l制的图元数? d后向~冲?
HRESULT DrawPrimitiveup() 可以直接?
HRESULT Preesent(复制源的矩Ş区域指针Q复制目的地的矩形区域指针,D3D讑֤H口句柄Q最更新区域指? 屏幕{
HRESULT SetIndices(使用的烦引缓冲区指针) 讄当前l制的烦引数l?
DrawIndexedPrimitive(囑օcdQ绘制到的烦引缓冲区的开始地址Q最的索引数组元素的|点的数目,开始的索引数组元素的|l制的数? 同DrawPrimitive()
l制函数
HRESULT DrawPrimitive(基本囑օcdQv始顶点,l制的图元的数量) 囑օl制
HRESULT Clear(清楚的矩形区域数量,清除的D行区域数l指针,清楚哪个~冲区,清除后重|的颜色Q清除后重置的深度,0-1.0Q重|的摸版? 清空囑Şl制?
HRESULT BeginScene() 开始绘?
HRESULT EndScene() l束l制
U理函数
CreateTexture() 创徏D3DU理对象
LoadBmpTetureQ) 装蝲文理函数
LoadBmpTexture24Bit (LPDIRECT3DDEVICE9 pDevice,LPCSTR pSrcFile,LPDIRECT3DTEXTURE9* ppTexture) 24位纹?
D3DXCreateTextureFromFile(D3D讑֤指针Q纹理图形文Ӟ存储D3D文理的指针地址) 直接从磁盘获取纹?
D3DXCreateTextureFromFileEx(D3D讑֤指针Q纹理图形文Ӟ指定U理宽,高,指定渐进U理序列U数Q纹理用方式一般ؓ0Q指定纹理图形格式,U理存放的内存类型一般位?Q纹理过滤方式,自动生成的纹理序列过滤方式,讄透明Ԍ囑Ş文g信息存放地址可设|?Q调色板存储地址Q创建的D3D文理的指针地址) 高获取U理
HRESULT SetTexture(多U理的烦?-7QD3D的纹理接口指? 讄当前要渲染的U理
HRESULT SetTextureStageState(多U理的烦引,U理渲染状态的cdQ纹理渲染状态的|与类型相对应) 讄U理的渲染状?
HRESULT SetSamplerState(指定U理属?-7Q纹理采样属性类型,讄U理采样属? U理采样
HRESULT CheckDeviceFormat(指定昑֍序列?D3D讑֤cd,指定昄模式格式Q缓冲区属性,需要用查询的格式的设备类?需要查询的昄格式) U理压羃
HRESULT LockRect(指定加锁的纹理别,指向D3DLOCKED_RECTl构Q要加锁的RECT区域-0代表整个区域Q加锁类??或下表的? 锁定U理
HRESULT UnlockRect(解锁的纹理? 解锁U理
向量函数
D3DXVECTOR3 * D3DXVer3Length(V) 向量模的计算
D3DXVECTOR3 * D3DXVec3NormalizeQ返回指针,VQ?单位?
D3DXVECTOR3 * D3DXVec3Add(q回的指针,u,v) 向量加法
D3DXVECTOR3 * D3DXVec3SubtractQ同上) 减法
D3DXVECTOR3 * D3DXVec3Cross(同上) 向量X?
D3DXVECTOR3 * D3DXVec3Lerp(同上) C
D3DXVECTOR3 * D3DXVec3MaximizeQ同上) 取最大?
D3DXVECTOR3 * D3DXVec3MinimizeQ同上) 取最?
D3DXVECTOR3 * D3DXVec3ScaleQ返回指针,PVQFLOATQ?比例
FLOAT D3DXVec3Dot(pv1,pv2) 点乘
参见~程_a.chm中的COM中模块的导出函数
Private Type D3DVECTOR
x As Single
y As Single
z As Single
End Type
'q回3D向量的规格化向量
Private Declare Function D3DXVec3Normalize Lib "DX8VB.DLL" Alias "VB_D3DXVec3Normalize" (VOut As D3DVECTOR, v As D3DVECTOR) As Long
Private Declare Function D3DXVec3Add Lib "DX8VB.DLL" Alias "VB_D3DXVec3Add" (VOut As D3DVECTOR, v1 As D3DVECTOR, V2 As D3DVECTOR) As Long
Private Declare Function D3DXVec3Subtract Lib "DX8VB.DLL" Alias "VB_D3DXVec3Subtract" (VOut As D3DVECTOR, v1 As D3DVECTOR, V2 As D3DVECTOR) As Long
Private Declare Function D3DXVec3Length Lib "DX8VB.DLL" Alias "VB_D3DXVec3Length" (v As D3DVECTOR) As Single
D3DFVF 自由点的格?
D3DFVF_DIFFUSE 包含谩反的信息
D3DFVF_NORMAL 包含法线信息
D3DFVF_PSIZE 点信息指明l制点的大小
D3DFVF_SPECULAR 包含镜面反射的信?
D3DFVF_XYZ 包含未经转换的顶点坐?
D3DFVF_XYZRHW 包含l过转换的顶点坐?
D3DFVF_XYZB1 through D3DFVF_XYZB5 包含用于骨骼动化的顶点和点寚w骼的权重信息
D3DFVF_XYZW 包含l过转换和裁剪的点坐标
D3DTRANSFORMSTATETYPE 变换的类?
D3DPRIMITIVETYPE 定义基本囑օ
D3DPT_POINTLIST 一l点的集?
D3DPT_LINELIST 一l线的集?
D3DPT_LINESTRIP 首尾相连的线D늚集合
D3DPT_TRIANGLELIST 一l三角Ş的集?
D3DPT_TRIANGLESTRIP 首尾相连的三角ŞQ有两个点集合
D3DPT_TRIANGLEFAN l成扇Ş的一l三角Ş集合
D3DPT_FORCE_DWORD 未定义的
D3DDISPLAYMODE 屏幕昄模式
D3DFMT_UNKNOWN 未知的象素格?
D3DFMT_R8G8B8 24位色QRGB各占8?
D3DFMT_A8R8G8B8 32位色Q@RGB各占8?
D3DFMT_X8R8G8B8 32位色QXZ??RGB各占8?
D3DFMT_R5G6B5 16位色QR?QG?QB??
D3DFMT_X1R5G5B5 16位色Q保?位,RGB各占5?
D3DFMT_A1R5G5B5 16位色Q@?位,RG5各占5?
D3DFMT_A4R4G4B4 16位色Q@RGB各占4?
D3DFMT_R3G3B2 8位色QR3,G3,B2?
D3DFMT_A8 只有8位@
D3DFMT_A8R3G3B2 16位色Q@8QR3QG3QB2?
D3DFMT_X4R4G4B4 16位色
D3DFMT_A2B10G10R10 32位色Q@?位,RGB?0?
D3DFMT_A8B8G8R8 32位色
D3DFMT_X8B8G8R8 32位色
D3DFMT_G16R16 32位色Q只有红和绿
D3DFMT_A2R10G10B10 32位色
D3DFMT_A16B16G16R16 64位色
D3DFMT_A8P8 8位色Q?位表C半透明Q?位表C颜?
D3DFMT_P8 8位色Q用牙色索引DC?
D3DFMT_L8 8位色Q只表示亮度
D3DFMT_L16 16位色Q只表示亮度
D3DFMT_A8L8 16位色Q?位表C半透明Q?位表CZ?
D3DFMT_A4L4 8位色Q?位表C半透明Q?位表CZ?
D3DDEVTYPE_HAL g抽象层,通过昄g来完成图形渲染工?
D3DDEVTYPE_NULLREF
D3DDEVTYPE_REF 参考光栅器Q一般用语测试显C卡不支持的D3D功能
D3DDEVTYPE_SW 用语支持W三方的软g
D3DDEVTYPE_FORCE_DWORD 扩展?
D3DCREATE 3Dq算的方?
D3DCREATE_ADAPTERGROUP_DEVICE
D3DCREATE_DISABLE_DRIVER_MANAGEMENT
D3DCREATE_DISABLE_DRIVER_MANAGEMENT_EX
D3DCREATE_FPU_PRESERVE Ȁzd_ֺ点q算或Q点运异常检,讄该项会降低系l性能
D3DCREATE_HARDWARE_VERTEXPROCESSING 由D3Dgq行点预算
D3DCREATE_MIXED_VERTEXPROCESSING 由合方式进行顶点运?
D3DCREATE_MULTITHREADED 支持多线E绘Ӟ讄该项会降低系l性能
D3DCREATE_NOWINDOWCHANGES
D3DCREATE_PUREDEVICE 用D3D的GET*Q)函数Q禁止D3D使用虚拟讑֤模拟点q算
D3DCREATE_SCREENSAVER
D3DCREATE_SOFTWARE_VERTEXPROCESSING 由D3D软gq行点q算
D3DSWAPEFFECT 取值列?
D3DSWAPEFFECT_DISCARD 后台~冲区复制到前台Ӟ清除后台~冲区内?
D3DSWAPEFFECT_FLIP 后台~冲区内容复制后Q保持不变,有多个后台缓冲区时?
D3DSWAPEFFECT_COPY 后台~冲区内容复制后Q保持不变,只有1个后台缓冲区时?
D3DSWAPEFFECT_FORCE_DWORD 该直作ؓ32位存储,通常不用
D3DPRESENT 屏幕反{模式列表
D3DPRESENT_DONOTWAIT
D3DPRESENT_INTERVAL_DEFAULT 默认的同ONE
D3DPRESENT_INTERVAL_ONE 当屏q刷Cơ时前台后台q行交换
D3DPRESENT_INTERVAL_TWO 当屏q刷Cơ时前台后台q行交换
D3DPRESENT_INTERVAL_THREE 当屏q刷Cơ时前台后台q行交换
D3DPRESENT_INTERVAL_FOUR 当屏q刷新四ơ时前台后台q行交换
D3DPRESENT_INTERVAL_IMMEDIATE 囑Şl制完成时立卌行交?
D3DPRESENT_LINEAR_CONTENT
D3DUSAGE ~冲区属性值列?
D3DUSAGE_AUTOGENMIPMAP
D3DUSAGE_DEPTHSTENCIL
D3DUSAGE_DMAP
D3DUSAGE_DONOTCLIP 用裁剪Q表C顶点缓冲区中的点不进行裁剪,当设|该属性时Q渲染状态D3DRS_CLIPPING必须设ؓFALSE
D3DUSAGE_DYNAMIC 使用动态内存分?
D3DUSAGE_NPATCHES 使用点~冲区绘制N-patches曲线
D3DUSAGE_POINTS 使用点~冲区绘制点
D3DUSAGE_RENDERTARGET
D3DUSAGE_RTPATCHES 使用点~冲区绘制曲U?
D3DUSAGE_SOFTWAREPROCESSING 使用软gq行点q算Q否则用硬件计?
D3DUSAGE_WRITEONLY 只写属性,不能q行L作,讄该属性可以提高系l性能
D3DPOOL ~冲源内存位|列?
D3DPOOL_DEFAULT 默认的,点~冲区尽可能存在与显存中
D3DPOOL_MANAGED 由D3D自动调度点~冲区内存位|(昑֭和内存)
D3DPOOL_SCRATCH 点~冲Z于计机的时内存中Q这U类型的点~冲Z能直接进行渲染,只能q行内存枷锁Q拷贝等操作
D3DPOOL_SYSTEMMEM 点~冲Z于内存中
D3DLOCK ~冲区加?
D3DLOCK_DISCARD 更新整个~冲?
D3DLOCK_DONOTWAIT
D3DLOCK_NO_DIRTY_UPDATE 在加锁的q程中系l进行其他操作(默认有Dirty标记)
D3DLOCK_NOOVERWRITE 保证不腹E缓冲区数据Q设|该属性可以立卌回内存指针,提高pȝ性能
D3DLOCK_NOSYSLOCK 在加锁的q程中系l可能执行其他操?
D3DLOCK_READONLY 讄~冲Z只读属?
D3DXVECTOR3 向量法
D3DXVECTOR3u(x,y,z);
D3DXVECTOR3v(x,y,z);
float 变量=D3DXVec3Dot(u指针,v指针) 点乘
D3DXMATRIX 矩阵
D3DXMatrixIdentity 单位矩阵
D3DXMatrixInverse 逆矩?
D3D实现囑Ş变换
D3DXMatrixTranslation q移矩阵
D3DXMatrixLockAtLH 观察矩阵
D3DXMatrixIdentity 一个矩阵单位化
D3DXMatrixRotationY lY轴{
D3DXMatrixRotationX lX轴{
D3DXMatrixRotationZ lZ轴{
D3DXMatrixScaling ~放变换
D3DXMatrixMuLationAxis 围绕L一个u旋{
D3DXMatrixMultiply l合变换
D3DUSAGE U理使用
D3DUSAGE_AUTOGENMIPMAP 自动生成多渐进U理序列Q该方式在资源处于D3DPOOL_SYSTEMMEM时无?
D3DUSAGE_DEPTHSTENCIL 深度模版~冲区,只在资源处于D3DPOOL_default时有?
D3DUSAGE_DMAP 该纹理是一个置换纹?
D3DUSAGE_DONOTCLIP
D3DUSAGE_DYNAMIC
D3DUSAGE_NPATCHES
D3DUSAGE_POINTS
D3DUSAGE_RENDERTARGET 该文理是一个渲染目标缓冲区
D3DUSAGE_RTPATCHES
D3DUSAGE_SOFTWAREPROCESSING 应用坐标变换
D3DUSAGE_WRITEONLY
D3DTEXTURESTAGESTATETYPE 渲染状态类?
D3DTSS_COLOROP 1 文理层的颜色混合方式
D3DTSS_COLORARG1 2 颜色混合的第一个参?
D3DTSS_COLORARG2 3 颜色混合的第二个参数
D3DTSS_ALPHAOP 4 指定U理层的Alpha透明
D3DTSS_ALPHAARG1 5 Alpha混合的第一个参?
D3DTSS_ALPHAARG2 6 Alpha混合的第二个参数
D3DTSS_BUMPENVMAT00 7 l制凹凸U理?
D3DTSS_BUMPENVMAT01 8 l制凹凸U理?
D3DTSS_BUMPENVMAT10 9 l制凹凸U理?
D3DTSS_BUMPENVMAT11 10 l制凹凸U理?
D3DTSS_TEXCOORDINDEX 11 该纹理层使用的纹理坐标的索引
D3DTSS_BUMPENVLSCALE 22 l制凹凸U理的羃攑֏?
D3DTSS_BUMPENVLOFFSET 23 l制凹凸U理的^Ud?
D3DTSS_TEXTURETRANSFORMFLAGS 24 控制U理坐标的{换标?
D3DTSS_COLORARG0 26 指定混合q程的第三个颜色
D3DTSS_ALPHAARG0 27 Alpha混合的第三个参数
D3DTSS_RESULTARG 28 颜色混合的结果输出寄存器
D3DTSS_CONSTANT 32 颜色混合的常量寄存器
D3DTSS_FORCE_DWORD 0x7fffffff 强制转换?2位,通常不用
D3DSAMPLERSTATETYPE U理采样属?
D3DSAMP_ADDRESSU 1 包装U理
D3DSAMP_ADDRESSV 2 包装U理
D3DSAMP_ADDRESSW 3 包装U理
D3DSAMP_BORDERCOLOR 4
D3DSAMP_MAGFILTER 5 处理攑֤qo
D3DSAMP_MINFILTER 6 处理~小qo
D3DSAMP_MIPFILTER 7 多纹理过?
D3DSAMP_MIPMAPLODBIAS 8 多文理U数偏移|初试直ؓ0
D3DSAMP_MAXMIPLEVEL 9 最大多U理U别Q初试gؓ0
D3DSAMP_MAXANISOTROPY 10 各向异性,初试gؓ1
D3DSAMP_SRGBTEXTURE 11
D3DSAMP_ELEMENTINDEX 12
D3DSAMP_DMAPOFFSET 13
D3DSAMP_FORCE_DWORD 0x7fffffff 强制转换32位,通常不用
U理d
D3DTADDRESS_WRAP 1 包装U理d
D3DTADDRESS_MIRROR 2 镜像U理d
D3DTADDRESS_CLAMP 3 夹取U理d
D3DTADDRESS_BORDER 4 Ҏ颜色U理d
D3DTADDRESS_MIRRORONCE 5 一ơ镜像纹理寻址
D3DTADDRESS_FORCE_DWORD 0x7fffffff强制转换32位,通常不用
世界变换
D3DTS_WORLD 世界变换
创徏ID3DXFont对象
使用接口ID3DXFontl制文本Q首先需要通过函数D3DXCreateFont()创徏ID3DXFont字体对象。ID3DXFont接口装了Windows字体和Direct3D讑֤指针QD3DXCreateFont()函数通过Windows字体和Direct3D讑֤指针创徏ID3DXFont对象Q该函数的声明如下:
Creates a font object for a device and font.
HRESULT D3DXCreateFont( LPDIRECT3DDEVICE9 pDevice, INT Height, UINT Width, UINT Weight, UINT MipLevels, BOOL Italic, DWORD CharSet, DWORD OutputPrecision, DWORD Quality, DWORD PitchAndFamily, LPCTSTR pFacename, LPD3DXFONT * ppFont);
Parameters
pDevice
[in] Pointer to an IDirect3DDevice9 interface, the device to be associated with the font object.
Height
[in] The height of the characters in logical units.
Width
[in] The width of the characters in logical units.
Weight
[in] Typeface weight. One example is bold.
MipLevels
[in] The number of mipmap levels.
Italic
[in] True for italic font, false otherwise.
CharSet
[in] The character set of the font.
OutputPrecision
[in] Specifies how Windows should attempt to match the desired font sizes and characteristics with actual fonts. Use OUT_TT_ONLY_PRECIS for instance, to ensure that you always get a TrueType font.
Quality
[in] Specifies how Windows should match the desired font with a real font. It applies to raster fonts only and should not affect TrueType fonts.
PitchAndFamily
[in] Pitch and family index.
pFacename
[in] String containing the typeface name. If the compiler settings require Unicode, the data type LPCTSTR resolves to LPCWSTR. Otherwise, the string data type resolves to LPCSTR. See Remarks.
ppFont
[out] Returns a pointer to an ID3DXFont interface, representing the created font object.
Return Values
If the function succeeds, the return value is S_OK. If the function fails, the return value can be one of the following: D3DERR_INVALIDCALL, D3DXERR_INVALIDDATA, E_OUTOFMEMORY.
Remarks
The creation of an ID3DXFont object requires that the device supports 32-bit color.
The compiler setting also determines the function version. If Unicode is defined, the function call resolves to D3DXCreateFontW. Otherwise, the function call resolves to D3DXCreateFontA because ANSI strings are being used.
If you want more information about font parameters, see The Logical Font.
CZ代码如下Q?/p>
D3DXCreateFont(g_device, 50, 20, 20, 0, FALSE, DEFAULT_CHARSET, 0, 0, 0, "Arial", &g_font);
OpenGL may be implemented by any combination of hardware and software. At the high-end, hardware may implement virtually all of OpenGL while at the low-end, OpenGL may be implemented entirely in software. In between are combination software/hardware implementations. More money buys more hardware and better performance.
Intro-level workstation hardware and the recent PC 3-D hardware typically implement point, line, and polygon rasterization in hardware but implement floating point transformations, lighting, and clipping in software. This is a good strategy since the bottleneck in 3-D rendering is usually rasterization and modern CPU's have sufficient floating point performance to handle the transformation stage.
OpenGL developers must remember that their application may be used on a wide variety of OpenGL implementations. Therefore one should consider using all possible optimizations, even those which have little return on the development system, since other systems may benefit greatly.
From this point of view it may seem wise to develop your application on a low-end system. There is a pitfall however; some operations which are cheep in software may be expensive in hardware. The moral is: test your application on a variety of systems to be sure the performance is dependable.
One should consider multiprocessing in these situations. By assigning rendering and computation to different threads they may be executed in parallel on multiprocessor computers.
For many applications, supporting multiprocessing is just a matter of partitioning the render and compute operations into separate threads which share common data structures and coordinate with synchronization primitives.
SGI's Performer is an example of a high level toolkit designed for this purpose.
Complexity may refer to the geometric or rendering attributes of a database. Here are a few examples.
Objects which are entirely outside of the field of view may be culled. This type of high level cull testing can be done efficiently with bounding boxes or spheres and have a major impact on performance. Again, toolkits such as Inventor and Performer have this feature.
Basically, one wants data structures which can be traversed quickly and passed to the graphics library in an efficient manner. For example, suppose we need to render a triangle strip. The data structure which stores the list of vertices may be implemented with a linked list or an array. Clearly the array can be traversed more quickly than a linked list. The way in which a vertex is stored in the data structure is also significant. High performance hardware can process vertexes specified by a pointer more quickly than those specified by three separate parameters.
Our first attempt at rendering this information may be:
We can still do better, however. If we redesign the data structures used to represent the city information we can improve the efficiency of drawing the city points. For example:
In the following sections the techniques for maximizing performance, as seen above, are explained.
After each of the following techniques look for a bracketed list of symbols which relates the significance of the optimization to your OpenGL system:
Example:
This is a very bad construct. The following is much better:
Wrong:
Example:
Note that software implementations of OpenGL may actually perform these operations faster than hardware systems. If you're developing on a low-end system be aware of this fact. [H,L] The It may be worthwhile to experiment with different visuals to determine if there's any advantage of one over another. Synchronization hurts performance. Therefore, if you need to render with both OpenGL and native window system calls try to group the rendering calls to minimize synchronization.
For example, if you're drawing a 3-D scene with OpenGL and displaying text with X, draw all the 3-D elements first, call Also, when responding to mouse motion events you should skip extra motion events in the input queue. Otherwise, if you try to process every motion event and redraw your scene there will be a noticable delay between mouse input and screen updates.
It can be a good idea to put a print statement in your redraw and event loop function so you know exactly what messages are causing your scene to be redrawn, and when.
Don't do this:
Do this:
Performance evaluation is a large subject and only the basics are covered here. For more information see "OpenGL on Silicon Graphics Systems".
After bottlenecks have been identified the techniques outlined in section 3 can be applied. The process of identifying and reducing bottlenecks should be repeated until no further improvements can be made or your minimum performance threshold has been met.
Measure the performance of rendering in single buffer mode to determine how far you really are from your target frame rate.
1. Hardware vs. Software
2. Application Organization
At first glance it may seem that the performance of interactive OpenGL applications is dominated by the performance of OpenGL itself. This may be true in some circumstances but be aware that the organization of the application is also significant.
2.1 High Level Organization
Multiprocessing
Some graphical applications have a substantial computational component other than 3-D rendering. Virtual reality applications must compute object interactions and collisions. Scientific visualization programs must compute analysis functions and graphical representations of data.
Image quality vs. performance
In general, one wants high-speed animation and high-quality images in an OpenGL application. If you can't have both at once a reasonable compromise may be to render at low complexity during animation and high complexity for static images.
GL_NEAREST
sampling and glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST )
.
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE )
to inspect tesselation granularity and reduce if possible. Level of detail management and culling
Objects which are distant from the viewer may be rendered with a reduced complexity model. This strategy reduces the demands on all stages of the graphics pipeline. Toolkits such as Inventor and Performer support this feature automatically.
2.2 Low Level Organization
The objects which are rendered with OpenGL have to be stored in some sort of data structure. Some data structures are more efficient than others with respect to how quickly they can be rendered.
An Example
Suppose we're writing an application which involves drawing a road map. One of the components of the database is a list of cities specified with a latitude, longitude and name. The data structure describing a city may be:
struct city {
float latitute, longitude; /* city location */
char *name; /* city's name */
int large_flag; /* 0 = small, 1 = large */
};
A list of cities may be stored as an array of city structs.
void draw_cities( int n, struct city citylist[] )
{
int i;
for (i=0; i < n; i++) {
if (citylist[i].large_flag) {
glPointSize( 4.0 );
}
else {
glPointSize( 2.0 );
}
glBegin( GL_POINTS );
glVertex2f( citylist[i].longitude, citylist[i].latitude );
glEnd();
glRasterPos2f( citylist[i].longitude, citylist[i].latitude );
glCallLists( strlen(citylist[i].name),
GL_BYTE,
citylist[i].name );
}
}
This is a poor implementation for a number of reasons:
Here's a better implementation:
glPointSize
is called for every loop iteration.
glBegin
and glEnd
void draw_cities( int n, struct city citylist[] )
{
int i;
/* draw small dots first */
glPointSize( 2.0 );
glBegin( GL_POINTS );
for (i=0; i < n ;i++) {
if (citylist[i].large_flag==0) {
glVertex2f( citylist[i].longitude, citylist[i].latitude );
}
}
glEnd();
/* draw large dots second */
glPointSize( 4.0 );
glBegin( GL_POINTS );
for (i=0; i < n ;i++) {
if (citylist[i].large_flag==1) {
glVertex2f( citylist[i].longitude, citylist[i].latitude );
}
}
glEnd();
/* draw city labels third */
for (i=0; i < n ;i++) {
glRasterPos2f( citylist[i].longitude, citylist[i].latitude );
glCallLists( strlen(citylist[i].name),
GL_BYTE,
citylist[i].name );
}
}
In this implementation we're only calling glPointSize twice and we're maximizing the number of vertices specified between glBegin
and glEnd
.
struct city_list {
int num_cities; /* how many cities in the list */
float *position; /* pointer to lat/lon coordinates */
char **name; /* pointer to city names */
float size; /* size of city points */
};
Now cities of different sizes are stored in separate lists. Position are stored sequentially in a dynamically allocated array. By reorganizing the data structures we've eliminated the need for a conditional inside the glBegin/glEnd
loops. Also, we can render a list of cities using the GL_EXT_vertex_array
extension if available, or at least use a more efficient version of glVertex
and glRasterPos
.
/* indicates if server can do GL_EXT_vertex_array: */
GLboolean varray_available;
void draw_cities( struct city_list *list )
{
int i;
GLboolean use_begin_end;
/* draw the points */
glPointSize( list->size );
#ifdef GL_EXT_vertex_array
if (varray_available) {
glVertexPointerEXT( 2, GL_FLOAT, 0, list->num_cities, list->position );
glDrawArraysEXT( GL_POINTS, 0, list->num_cities );
use_begin_end = GL_FALSE;
}
else
#else
{
use_begin_end = GL_TRUE;
}
#endif
if (use_begin_end) {
glBegin(GL_POINTS);
for (i=0; i < list->num_cities; i++) {
glVertex2fv( &position[i*2] );
}
glEnd();
}
/* draw city labels */
for (i=0; i < list->num_cities ;i++) {
glRasterPos2fv( list->position[i*2] );
glCallLists( strlen(list->name[i]),
GL_BYTE, list->name[i] );
}
}
As this example shows, it's better to know something about efficient rendering techniques before designing the data structures. In many cases one has to find a compromize between data structures optimized for rendering and those optimized for clarity and convenience.
3. OpenGL Optimization
There are many possibilities to improving OpenGL performance. The impact of any single optimization can vary a great deal depending on the OpenGL implementation. Interestingly, items which have a large impact on software renderers may have no effect on hardware renderers, and vice versa! For example, smooth shading can be expensive in software but free in hardware While glGet*
can be cheap in software but expensive in hardware.
3.1 Traversal
Traversal is the sending of data to the graphics system. Specifically, we want to minimize the time taken to specify primitives to OpenGL.
GL_LINES, GL_LINE_LOOP, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN
, and GL_QUAD_STRIP
require fewer vertices to describe an object than individual line, triangle, or polygon primitives. This reduces data transfer and transformation workload. [all]
glVertex/glColor/glNormal
calls with the vertex array mechanism may be very beneficial. [all]
glVertex
, glColor
, glNormal
and glTexCoord
glVertex
, glColor
, etc. functions which take a pointer to their arguments such as glVertex3fv(v)
may be much faster than those which take individual arguments such as glVertex3f(x,y,z)
on systems with DMA-driven graphics hardware. [H,L]
glNormal
. If texturing is disabled don't call glTexCoord
, etc.
glBegin/glEnd
glBegin/glEnd
.
glBegin( GL_TRIANGLE_STRIP );
for (i=0; i < n; i++) {
if (lighting) {
glNormal3fv( norm[i] );
}
glVertex3fv( vert[i] );
}
glEnd();
if (lighting) {
glBegin( GL_TRIANGLE_STRIP );
for (i=0; i < n ;i++) {
glNormal3fv( norm[i] );
glVertex3fv( vert[i] );
}
glEnd();
}
else {
glBegin( GL_TRIANGLE_STRIP );
for (i=0; i < n ;i++) {
glVertex3fv( vert[i] );
}
glEnd();
}
Also consider manually unrolling important rendering loops to maximize the function call rate. 3.2 Transformation
Transformation includes the transformation of vertices from glVertex
to window coordinates, clipping and lighting.
GL_SHININESS
material parameter. [L,S]
glEnable/Disable(GL_NORMALIZE)
controls whether normal vectors are scaled to unit length before lighting. If you do not use glScale
you may be able to disable normalization without ill effects. Normalization is disabled by default. [L,S]
GL_LINES
, GL_LINE_LOOP
, GL_TRIANGLE_STRIP
, GL_TRIANGLE_FAN
, and GL_QUAD_STRIP
decrease traversal and transformation load.
glRect
usage
glBegin(GL_QUADS)
... glEnd()
instead. [all] 3.3 Rasterization
Rasterization is the process of generating the pixels which represent points, lines, polygons, bitmaps and the writing of those pixels to the frame buffer. Rasterization is often the bottleneck in software implementations of OpenGL.
3.4 Texturing
Texture mapping is usually an expensive operation in both hardware and software. Only high-end graphics hardware can offer free to low-cost texturing. In any case there are several ways to maximize texture mapping performance.
GL_UNSIGNED_BYTE
component format is typically the fastest for specifying texture images. Experiment with the internal texture formats offered by the GL_EXT_texture
extension. Some formats are faster than others on some systems (16-bit texels on the Reality Engine, for example). [all]
GL_NEAREST
or GL_LINEAR
then there's no reason OpenGL has to compute the lambda value which determines whether to use minification or magnification sampling for each fragment. Avoiding the lambda calculation can be a good performace improvement.
GL_DECAL
or GL_REPLACE_EXT
functions for 3 component textures is a simple assignment of texel samples to fragments while GL_MODULATE
is a linear interpolation between texel samples and incoming fragments. [S,L]
glTexImage2D
to repeatedly change the texture. Use glTexSubImage2D
or glTexCopyTexSubImage2D
. These functions are standard in OpenGL 1.1 and available as extensions to 1.0. 3.5 Clearing
Clearing the color, depth, stencil and accumulation buffers can be time consuming, especially when it has to be done in software. There are a few tricks which can help.
glClear
carefully [all]
glClear
.
glClear( GL_COLOR_BUFFER_BIT );
if (stenciling) {
glClear( GL_STENCIL_BUFFER_BIT );
}
Right:
if (stenciling) {
glClear( GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
}
else {
glClear( GL_COLOR_BUFFER_BIT );
}
glScissor()
to restrict clearing to a smaller area. [L].
int EvenFlag;
/* Call this once during initialization and whenever the window
* is resized.
*/
void init_depth_buffer( void )
{
glClearDepth( 1.0 );
glClear( GL_DEPTH_BUFFER_BIT );
glDepthRange( 0.0, 0.5 );
glDepthFunc( GL_LESS );
EvenFlag = 1;
}
/* Your drawing function */
void display_func( void )
{
if (EvenFlag) {
glDepthFunc( GL_LESS );
glDepthRange( 0.0, 0.5 );
}
else {
glDepthFunc( GL_GREATER );
glDepthRange( 1.0, 0.5 );
}
EvenFlag = !EvenFlag;
/* draw your scene */
}
3.6 Miscellaneous
glGetFloatv, glGetIntegerv, glIsEnabled, glGetError, glGetString
require a slow, round trip transaction between the application and renderer. Especially avoid them in your main rendering code.
glPushAttrib
glPushAttrib( GL_ALL_ATTRIB_BITS )
in particular can be very expensive on hardware systems. This call may be faster in software implementations than in hardware. [H,L]
glGetError
inside your rendering/event loop to catch errors. GL errors raised during rendering can slow down rendering speed. Remove the glGetError
call for production code since it's a "round trip" command and can cause delays. [all]
glColorMaterial
instead of glMaterial
glColorMaterial
may be faster than glMaterial
. [all]
glDrawPixels
glDrawPixels
often performs best with GL_UNSIGNED_BYTE
color components [all]
glDrawPixels
. [all]
glPolygonMode
glBegin
with GL_POINTS, GL_LINES, GL_LINE_LOOP
or GL_LINE_STRIP
instead as it can be much faster. [all] 3.7 Window System Integration
glXMakeCurrent
call, for example, can be expensive on hardware systems because the context switch may involve moving a large amount of data in and out of the hardware.
GLX_EXT_visual_rating
extension can help you select visuals based on performance or quality. GLX 1.2's visual caveat attribute can tell you if a visual has a performance penalty associated with it.
glXWaitX
and glXWaitGL
functions serve this purpose.
glXWaitGL
to synchronize, then call all the X drawing functions.
3.8 Mesa-specific
Mesa is a free library which implements most of the OpenGL API in a compatible manner. Since it is a software library, performance depends a great deal on the host computer. There are several Mesa-specific features to be aware of which can effect performance.
MESA_RGB_VISUAL
environment variable can be used to determine the quickest visual by experimentation.
glColor
command should be put before the glBegin
call.
glBegin(...);
glColor(...);
glVertex(...);
...
glEnd();
glColor(...);
glBegin(...);
glVertex(...);
...
glEnd();
glColor[34]ub[v]
are the fastest versions of the glColor
command.
4. Evaluation and Tuning
To maximize the performance of an OpenGL applications one must be able to evaluate an application to learn what is limiting its speed. Because of the hardware involved it's not sufficient to use ordinary profiling tools. Several different aspects of the graphics system must be evaluated.
4.1 Pipeline tuning
The graphics system can be divided into three subsystems for the purpose of performance evaluation:
At any given time, one of these stages will be the bottleneck. The bottleneck must be reduced to improve performance. The strategy is to isolate each subsystem in turn and evaluate changes in performance. For example, by decreasing the workload of the CPU subsystem one can determine if the CPU or graphics system is limiting performance.
4.1.1 CPU subsystem
To isosulate the CPU subsystem one must reduce the graphics workload while presevering the application's execution characteristics. A simple way to do this is to replace glVertex()
and glNormal
calls with glColor
calls. If performance does not improve then the CPU stage is the bottleneck.
4.1.2 Geometry subsystem
To isoslate the geometry subsystem one wants to reduce the number of primitives processed, or reduce the transformation work per primitive while producing the same number of pixels during rasterization. This can be done by replacing many small polygons with fewer large ones or by simply disabling lighting or clipping. If performance increases then your application is bound by geometry/transformation speed.
4.1.3 Rasterization subsystem
A simple way to reduce the rasterization workload is to make your window smaller. Other ways to reduce rasterization work is to disable per-pixel processing such as texturing, blending, or depth testing. If performance increases, your program is fill limited.
4.2 Double buffering
For smooth animation one must maintain a high, constant frame rate. Double buffering has an important effect on this. Suppose your application needs to render at 60Hz but is only getting 30Hz. It's a mistake to think that you must reduce rendering time by 50% to achive 60Hz. The reason is the swap-buffers operation is synchronized to occur during the display's vertical retrace period (at 60Hz for example). It may be that your application is taking only a tiny bit too long to meet the 1/60 second rendering time limit for 60Hz.
4.3 Test on several implementations
The performance of OpenGL implementations varies a lot. One should measure performance and test OpenGL applications on several different systems to be sure there are no unexpected problems.
我个h来说3ds max 8脚本调试器用得不多,在这里我讲一下脚本调试器的原理和单的用法。脚本调试器只不q是一个max8的一个调试程序,它允许暂?ds maxȝE和其它U程Q可以用命令threads昄当前?ds max所有线E及U程idQ可以用setThread U程ID)切换当前调试的线E。一般情况调试器默认试最层(q个词不知道大家是否理解我的意思,像是家里面的菜盘子Q最层的盘子是最后放上去的,当然要拿开盘子只能从最上面一个开?的线E,3ds max本n在实C些操作时大量使用多线E,例如渲染Ӟ创Z一个新U程Q关于线E和q程的区别,你可以找相应~程书籍。在3ds max8的目前调试器版本Q还不支持鼠标选择某行讄断点Q至我没有扑ֈq个功能Q你扑ֈ了请告诉我)Q因此我现在断定Q这是一个不实用的工兗但?ds max8已经为我们提供了q个工具Q当然是有用的了Q只不过E稍ȝ?br> 使用脚本调试器(我假设你已经写好了一个脚本)Q首先在你的脚本你想要暂停的地方讄断点Q设|断点可以用break()函数Q也是当脚本运行到q里时暂停程序。这样当你运行这个脚本时你将会在脚本调试器的"输出"~辑H口中显C线E相应的内容。(我个为每q行一个脚本,3ds max׃ؓq个脚本创徏一个线E,所以才可以使用脚本调试器来跟踪脚本。谁能证实一下我的猜?我的E-MAIL: liyingjang@21cn.comQ。当脚本执行C讄断点处就停下来,q时你可以用getVar ""?setVar "" 来查看变量内容和临时讄变量内容。更方便查看变量内容的方法可以点?监视"按钮Q然后输入变量名按回车键卛_昄你刚输入的变量名的g。点?q行"按钮可以使脚本运行到下一个断点处暂停Q查看和讄变量的方法上一步所说的是一栗?br> ȝ一下:3ds max8的目前的调试器还很不完善Q你也可以用丑陋来Ş容,希望以后的Max版本能把脚本调试器做得好点,好可惜我没有看到在MAX9调试器有一点点的变化)。脚本调试器虽不怎么P但也不是一无是处,臛_你可以少用print和format来查看运行时变量内容和调试脚本?br> 以下是我写了一个简单的调试脚本Q运行后当i=10时会启动脚本调试器?br>global ps=10
for i=0 to 100 do
(
ps = ps + i
if i==10 do break()
)
查看q行时断点的i变量Q可以点?监视"按钮Q输入i 然后回RQ就可以看到变量i的gؓ10?/p>
已有大量优秀的基于多边Ş的地形渲染算法。比较经典的法?/span>M. Duchaineau{h提出ROAM法。这个算法采用一三角二叉树来描q整个地形。一个地形在最初的层次上由两个较大的等腰直角三角Şl成Q这两个{腰直角三角形可以被不断地细分来展现地Ş的更多细节。每一ơ细分过E都向直角三角Ş的斜边的中点处增加一个由高程数据所描述的顶点,该点所在的直角三角形一分ؓ二,同时该算法也定义了一些规则来保证地Ş中不会因盔R两个三角形细节层ơ的不同而出现裂~。这个算法已被许多游戏所采用。还有一cȝ法,通过地形在X-Z投媄面上不断地规则细分来得到不同的细节,q就是本文要介绍的四叉树I间划分法。另外,最新提出的一个地形算法也不得不提QHugues Hoppe?/font>2004q提出的几何裁剪图方?Geometry Clipmaps)Q算法用了最新硬件所支持的顶点纹理来定义地Ş的外观,q且对于距离摄媄Z同远q的地方采用不同的纹理层Q最大限度地使用g加速了地Ş渲染的过E。这个方法听h非常妙Q但它目前只被较的g支持。因为顶点纹理是Shader Model 3.0才支持的功能Q也是说只有DirectX 9.0cU别的显卡才能支持这U算法。这对于某些有普及性要求的囑Ş应用E序Q尤其是Ҏ戏来讲不是一件好的事情。因此大多数人现在还在用经典的地Ş渲染Ҏ?/span>
首先Q基于四叉树的地形渲染方法用高E数据作为数据源。且法要求高程数据的大必Mؓ2n+1的正方Ş。所谓高E数据,卌彩范围在0-255的灰度图片,不同的灰度代表了不同的高度倹{如果某高程数据指出q个高程数据最高处的Y坐标值是4000Q那么在高程数据中一个gؓ255的像素点pC个点所代表的地形区域的高度?000Q同理如果该像素值是127那么pC个点所代表的地形区域的高度?000×(127/255)=2000。高E数据的每个像素都对应所渲染|格中的一个顶炏V另外还有一个参数描q顶点与点之间的水q,以及一个描q最大高度的参数。因此地形的基本数据l构如下Q?/span>
struct Terrain
{
char **DEM; //一个描q高E数据的二维数组
float CellSpace;
float HeightScale;
}
其中Q各变量的具体意义如下图所C:
有了q些参数Q我们可以很Ҏ地由高程数据的参数值得到它所表述的多边Ş|格。得到这个网g后,可以单地把它攑օ点数组QƈZ建立一个顶点烦引,可以传入硬件进行渲染了。然而,事情q不是这么简单。对于较尺寸的高程数据(?29×129)Q这样做实可行Q但随着高程数据规模的增大,所需的顶Ҏ和描q网格的三角形数会急剧膨胀。这个数值很快就会大到最新的昑֍也无法接受。比如一?025×1025的高E数据,我们需?025×1025=1050625个顶点,以及1050625×2=2101250个三角Ş。就你的显卡每U能够渲?000万个三角形,你也只能得到不到5fps的渲染速度Q况且你的场景可能还不只包括地Ş。因此我们必L办法在不影响视觉效果的情况下~减所渲染的三角Ş数量Q另外还应该注意一ơ性将最多的数据预先传给g以节U带宽?/span>
q里要讲解的法Q目的就是在不媄响或在视觉可以接受的范围内羃减所渲染三角形的数量Q以辑ֈ实时渲染的要求。根据测试,本算法在漫游大小?025*1025的地形时速度E_?50fps以上(在nVidia Geforce 6200 + P4 1.6GHz的硬件上得到)?/span>
׃地Ş覆盖范围q,但它的投影在XZq面上均匀分布(以下采用OpenGL中的x坐标p,Y轴ؓ竖直向上的坐标u)Q因此我们有必要考虑对地形进行空间划分。正是由于这L均匀分布Q给我们的划分过E带来了便利。我们不需要具体地d割某个三角ŞQ只要选择那些q顶点且和X或Z轴垂直的q面作ؓ划分面即可。例如对于一个高E数据,我们可以以坐标原点作为地形的中心点,然后沿着X轴和Z轴依ơ展开来分布各个顶炏V如下如所C?/span>
首先Q我们可以选择X=0和Z=0q两个^面,地形划分ؓ{大的四个区域,然后对划分出来的四个子区域进行递归划分Q每ơ划分都选择交于区域中心点ƈ且互相垂直的两个q面作ؓ划分面,直到每个子区域都只包含一个地形单元块Q即两个三角形)而不能再划分为止。例如对于上图所C?*9大小的地形块Q经q划分之后如下图所C:
由图可知Q只有高E数据满?cite style="FONT-STYLE: normal">大小2n+1的正方Şq个条gQ我们才可能对地形进行均匀划分?/cite>我们可以把划分结果用一|来表qͼ׃每次划分之后产生四个子节点,因此q棵树叫四叉树。那么,q棵树中应该存储那些信息呢?首先对于每个节点Q应该指定这个节Ҏ代表的地形的区域范围。ƈ不是把地形网g实际的顶Ҏ入树中,而是要在树中说明q个节点覆盖了地形的那些区域。比如一个子节点应该有一个Center(X,Y)变量Q指定这个节点的中心Ҏ对应的顶点烦引,或编受ؓ了方便v见,可以把地形中心点~号?0,0)然后沿着坐标轴递增。此外还要有个变量指定这个节点到底覆盖了地Ş的多个点。如下图所C?/span>
我们目前的四叉树的数据结构如下:
struct QuadTreeNode
{
QuadTreeNode *Children[4];
int CenterX,CenterY;
int HalfRange;
}
有了四叉树之后,如何利用它的优势呢?首先我们考虑单的视见体裁?View Frustum CullingQ以下简UVFC)。相信很多接触过基本囑Ş优化的h都应该熟悉VFCQVFC的作用既是对那些明显位于可见qx头体之外的多边Ş在把它们传给昑֍之前剔除掉。这个过E由CPU来完成。虽然简单,但它却非常有效。VFCq程如下Q?/span>
1.为每个节点计包围球。包围球可以单的以中心顶点ؓ球心Q最大坐标值点(节点所覆盖的所有顶点的最大X、Y、Zg为此点的坐标?到球心的距离为半径?/span>
2.Ҏ当前的投影和变换矩阵计算此时可视qx头体的六个^面方E。这一步可以参考Azure的Blog上的一文章,q篇文章l出了VFC的具体代码?a target=_blank>单击q里?/span>
3.从树的根l点以深度优先的序遍历树。每ơ访问节ҎQ测试该节点包围球与视见体的怺情况。在下面的情况下Q包围球与视见体怺Q?/span>
1) 球心在六个^面所包围的凸状区域内部?br> 2) 球心在六个^面所包围的凸状区域外部,但球心到某个q面的距d于半径?/span>
4.如果怺试昄包围球和视见体存在交集,l箋递归遍历此节点的4个子节点Q如果此节点已经是叶节点Q则q个节点应被l制。如果不存在交集Q放弃这个节点,对于q个节点的所有子节点不再递归查。因为如果一个节点不可见Q那么其子节点一定不可见?/span>
q样Q我们剔除了那些不在视见体内的地形区域,节约了一些资源。但q还不够。在某些情况下,VFC可能q会指出整个地Ş都可见,在这U情况下Q将q么多三角Ş都画出显然是不可取的?/span>
因此q要考虑地Ş的细节层?LOD)。我们应该考虑刎ͼ地Ş不可能所有部分都一样^坦或陡峭。对于^坦的部分Q我们用q多的三角ŞLq是没有意义的。而对于v伏程度较大的区域Q只有较多的三角形数量才不让人感到尖锐的p。再者,无论地Ş起伏E度如何Q那些距视点很q的区域Q也没有必要p太多的资源去渲染Q毕竟它们投影到屏幕上的面积很小Q对其进行简化也是必要的?/span>
既然我们要对起伏E度不同的区域采用不同的l节U别Q我们首先必LCU描q地形v伏程度的量。与其说起伏E度Q不如说是地形的某个点因ؓ被简化后而生的误差。要计算q个误差Q我们先要了解地形是如何被简化的?/span>
考虑下图所C的地Ş块,它的渲染l果如下囑֏图所C?/span>
现在如果要对所需渲染的三角Şq行化,我们可以考虑q个地Ş块每条边中间的顶?下图左侧U色?Q?/span>
如果这些红色的点剔除Q我们可以得C囑֏ҎC的化后的网根{误差就在这一步生。由于红色的点被剔除后Q原本由U色点所表示的地形高度现在变成了两侧黑色点插值后的高度。这个高度就是误差。如下图?/span>
因此Q对于每个节点,我们先计这个节Ҏ有边中点被删除后所造成的误差,分别CؓΔH1, ΔH2, ΔH3, ΔH4。如果这个节点包含子节点Q递归计算子节点的误差Qƈ把四个子节点的误差记?#916;Hs1, ΔHs2, ΔHs3, ΔHs4。这个节点的误差是q八个误差g的最大倹{由于这是一个递归的过E,因此应该把这个过E加到四叉树的生成过E中Qƈ向四叉树的数据结构中加入一个误差变量。如下?/span>
struct QuadTreeNode
{
QuadTreeNode *Children;
int CenterX,CenterY;
int HalfRange;
float DeltaH; //节点误差?br> }
下面来看一下地形的具体渲染q程?/span>
首先Q我们位于四叉树的根l点。我们此时考虑根结点的误差Q如果这个误差小于一个阈|直接使用根结点的中心点以及此节点的四个边角点作ؓ点渲染一个三角扇形,q个三角扇Ş是渲染出来的地形。但是更l常的情况下Q根l点的误差值是很大的,因此法认ؓ要对根结点进行细分,以展现更多细节。于是对于根l点的每个子节点Q重复这个步骤,x查它的误差值是否大于阈|如果大于Q直接渲染这个节点,如果于Q递归l分节点。目前我们的法伪代码如下?/span>
procedure DrawTerrain(QuadTreeNode *node)
{
if (node->DeltaH > k)
{
for (i=0;i<4;i++)
{
DrawTerrain(node->Children[i]);//递归划分
}
}
else
{
GraphicsAPI->DrawPrimitive(node);//以节点的中心点和四个边角点绘制三角扇?
}
}
q个伪代码在一个较高的层次上表qC法的基本思想。然而我们还有许多问题要考虑。其一是目前我们仅仅考虑了地形的l节层次和地形表面v伏程度的关系Q但q应该考虑地Ş块距视点远q跟地Şl节层次的关pR解册个问题很单,我们只需在伪代码的条件中加入距离q一因素卛_。即?/span>
if (node->DeltaH > k)
{
...
}
else ...
改ؓQ?/span>
if (node->DeltaH / d > k)
{
...
}
else ...
其中d点中心点与视点之间的距离。而事实上Q当l节E度与距ȝqx成反比时Q能够减更多的三角形,而且视觉效果更好Q只要阈值k讄得当Q根本感觉不出地形因点的Ud而发生几何Ş变。因此,我们最l的条g式ؓQ?/span>
node->DeltaH / d2 > k
q有一个很重要的问题,是q个法所产生的地形会因ؓ节点之间l节层次的不同而生裂~。下图说明了裂缝的生原因?/span>
有两个方法可以解册个问题,一个方法是删除左侧节点中生裂~的点Q两条边能够重合。另一U方法是Zؓ地在右侧地Ş块中插入一条边Q这条边q接中心点和造成裂缝的顶点,从而消除裂~。在渲染地ŞӞ可以采取下面的办法避免裂~的产生Q?/span>
1.在预处理阶段Qؓ所有顶点创Z个标记数l,标记以该点Z心点的节点在某一帧是否被l分。如果被l分则标Cؓ1Q否则标??/span>
2.从根节点开始,以广度优先的序遍历四叉树,使用之前提出的条件式判断节点是否需要分剌Ӏ如果公式表明需要分Ԍq且与节点相ȝ四个节点的中心点都被标记?Q那么把q个节点及其四个子节点的标记设ؓ1Qƈ递归l分q个节点。否则,这个节点的标记设ؓ1Q把q个节点的四个子节点的标记设?Q然后采用下面的Ҏl制q个地Ş块:
1)节点的中心点和四个边角点d到即绘制的三角扇Ş列表中?br> 2)依次查与四条边相ȝ节点的标记数l,如果相应的标Cؓ1Q那么将该点dC角扇形的点列表中,否则跌该点?br> 3)l制三角扇Ş?/span>
我们最l的伪代码如下?/span>
bool IsNodeInFrustum(QuadTreeNode *node) { return (node->BoudingSphere in frustum); } bool NeighbourIsValid(QuadTreeNode *node) { return (all four neighbours of node are identified as 1) } void RenderTerrain() { list<QuadTreeNode *>next,current,draw; int level =0; { for each thisNode in current { if (thisNode->DeltaH/(distance*distance) > k && NeighbourIsValid(thisNode) ) { SetFlag(thisNode,1); for j= 1 to 4 { next.push_back(thisNode->Children[j]); SetFlag(thisNode->Children[j],1) } } else { SetFlag(thisNode,1); for j= 1 to 4 { draw.push_back(thisNode->Children[j]); SetFlag(thisNode->Children[j],0); } } } SwapList(current,next); level++; } GraphicsAPI->DrawPrimitives(draw); } |
另外Q一个重要的优化是利用硬件的~冲区或点数组(对于不支持顶点缓冲的g而言)。因为地形无论怎样化,点数据L固定不变的。我们在每一帧动态生的仅仅是顶点烦引,因此我们有必要实现将地Ş的所有顶Ҏ据输入到点~冲中,然后在渲染时一ơ性将所有的索引传给昑֍Q以提高速度。实验表明,使用点~冲比直接用glBegin/glEndl制囑Ş要快5倍以上?/span>
以上讲述了如何做到实时地渲染大型地Ş。主要应用了LOD和VFC两种手段来精三角形数量。然而VFC只能剔除不在视见体内的图形,而对于在视见体内但被其他更近的物体遮挡的情况却无能ؓ力。如果要实现地Ş的自遮挡剔除Q地q线法是一个好的选择。然而当你的场景不仅仅是包含地ŞӞ地^U算法也只能处理地Ş的自遮挡情况。因为地q线法只对2.5D的地?卛_XZq面上无重合投媄的场?有效。对于完?D场景Q地q线q不能很好的工作。所以当你在引擎中用地形时Q可以考虑地形分块后攑օ场景的管理树中,如BSP或Octree{。然后根据引擎的性质使用入口(Portal)、PVS或者遮挡测?Occlusion Culling){方法进行遮挡剔除。值得的是Q遮挡测试是一个非常灵zȝ实时的剔除算法,且无需M预计过E。但要想有效的实现它q不是一件容易的事。我曑ְ地Ş分块后用遮挡剔除来完成地Ş的自遮挡Q但是渲染速度不但没有提升Q反而有d的下降。因此如果要使用遮挡剔除的话必须和引擎结合v来统一q行遮挡试Q才有可能提高效率?/span>
现在你应该了解了基本的地形实时渲染方法。要惌地Ş的外观更加真实,我们q需要更多的工作。我们需要ؓ地Ş加上U理贴图和光照。首先考虑地Ş的光照。由于地形的多边形网格是实时产生的,它会随着视点的移动而变化,因此如果你直接用OpenGL内置的顶点光照,你会得到极度不稳定的光照效果。你会看到地形表面会因ؓ你的Ud而不断蟩动。因此我们必M用其他的光照Ҏ来避免这个问题。我们想C光照贴图。光照脓图是一个游戏中常用的光照技术。它是一个覆盖了场景中所有多边Ş的脓图。通过l脓图赋|我们可以得到多边形表面复杂的光照效果。用好的算法计出来的光照贴图可以模拟极度逼真的光影效果。它l我们带来的视觉享受q远地超q了OpenGL的内|光照。有兛_照脓囄计算可以参考我译的一文章:辐射度算?Radiosity)
你可以简单地为地形覆盖上单一的纹理,q看h些许增加了地形的真实性:
在上图中Q我们创Z一个地形,q运用了一个重复的U理。这个过E让地Ş的无论哪一个区域看h都是一LQ例如都是草圎ͼ。这昄不太真实Q也q于乏味。或怽会创Z一q超大的囄Q以拉覆盖的方式映到地Ş表面。这样做的后果是内存开销q于庞大Q这样做也很会受到硬件的限制。因此我们应该用一U更好的U理贴图方式Q纹理烦引脓图?/span>
U理索引贴图对三个可重复的纹理进行烦引脓图。所谓烦引脓图,是对三个可重复U理q行索引Q以军_地Ş的哪些区域需要用哪些纹理的混合来脓图。因为对于Q意的贴图Q都׃l包?个颜色通道Q即R、G、BQ的像素l成。用于烦引的贴图的像素ƈ不表C地形的某个区域的具体颜Ԍ而是表示地Ş的某个区域用何种具体的纹理脓图。因为具体的U理l节存储在这三个可重复的U理中,因此索引贴图的脓图方式也为拉伸到地Ş表面Q但它的分L率可以大大降低?/span>
U理索引贴图的工作方式如下:对于地Ş投媄到屏q上的像素,查找该像素所映射到烦引脓图上的像素。然后根据这一像素R、G、B分量的不同,军_R、G、B分量所代表的具体纹理脓囄混合因子。根据这个合因子合三个可重复贴图后,合得到的最l颜色D出到屏幕上?/span>
例如Qo索引贴图的R分量代表沙W的纹理,G分量代表草地QB分量代表岩石。如果烦引脓图上一个像素的值是(0,255,0)Q即l色Q则q个像素所对应的地形区域的具体U理׃ؓ草地。如果该像素颜色值是(127,127,0)Q即黄色Q则该像素所对应的地形区域的U理地和沙W的合,看v来既有草Q又有沙。又如下图显CZ一个样本烦引脓图,以及使用该脓囄引纹理之后的渲染效果?/span>
|
|
索引贴图QR=沙WQG=草地,B=岩石Q?/span> |
渲染效果 |
原理很简单,下面讲解一下具体的实现q程。首先,我们准备4个纹理,其中1个纹理烦引脓图,它将被拉伸覆盖整个地形,然后3张细节脓图,q将它们l定到相应的U理通道上。然后用Vertex Shader为每个顶点自动计烦引脓囄U理坐标Q在Fragment Shader里,对烦引脓图进行纹理查找,使用查找得到的颜色值的RGB颜色信息混合3张细节脓图,得到当前像素的颜艌Ӏ最后还应该把这个颜色和光照贴图中的值相乘,得到最l的l果。下面是相关的Shader代码Q用GLSL~写?/span>
Vertex Shader:
uniform float TexInc; //U理~放?用于查找索引U理 |
Fragment Shader:
uniform sampler2D IndexMap; |
最后,如果你对本文有不解之处,Ƣ迎和我共同讨论?/span>