当前位置: 首页 > 工具软件 > gfx > 使用案例 >

Gfx_BeginScene

尹俊贤
2023-12-01

 bool CALL HGE_Impl::Gfx_BeginScene(HTARGET targ)
{
        LPDIRECT3DSURFACE8 pSurf=0, pDepth=0; //D3D
表面指针
        D3DDISPLAYMODE Mode; //
显示结构体(屏幕宽度,屏幕高度,屏幕刷新率,当前层的显示模式版本)
        CRenderTargetList *target=(CRenderTargetList *)targ; //render链表

        HRESULT hr = pD3DDevice->TestCooperativeLevel();
        if (hr == D3DERR_DEVICELOST) return false; //
设备丢失,返回
        else if (hr == D3DERR_DEVICENOTRESET) //可以恢复设备
        {

                // 恢复设备
                if(bWindowed)
                {
                        if(FAILED(pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &Mode)) || Mode.Format==D3DFMT_UNKNOWN)
                        {
                                _PostError("Can't determine desktop video mode");
                                return false;
                        }

                        d3dppW.BackBufferFormat = Mode.Format;
                        if(_format_id(Mode.Format) < 4) nScreenBPP=16;
                        else nScreenBPP=32;
                }

            if(!_GfxRestore()) return false;
        }

        if(VertArray)
        {
                _PostError("Gfx_BeginScene: Scene is already being rendered");
                return false;
        }

        if(target != pCurTarget)
        {
                if(target)
                {
                        target->pTex->GetSurfaceLevel(0, &pSurf); //
获取纹理表面
                        pDepth=target->pDepth;
                }
                else
                {
                        pSurf=pScreenSurf;
                        pDepth=pScreenDepth;
                }
                if(FAILED(pD3DDevice->SetRenderTarget(pSurf, pDepth))) //
设置贴图表面
                {
                        if(target) pSurf->Release();
                        _PostError("Gfx_BeginScene: Can't set render target");
                        return false;
                }
                if(target)
                {
                        pSurf->Release();
                        if(target->pDepth) pD3DDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE ); //
绘制状态函数,DDRS_ZENABLE 用于控制深度缓存的状态

                        else pD3DDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
                        _SetProjectionMatrix(target->width, target->height); //
创建投影矩阵
                }
                else
                {
                        if(bZBuffer) pD3DDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );
                        else pD3DDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
                        _SetProjectionMatrix(nScreenWidth, nScreenHeight);
                }

                pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj); //
设置投影矩阵
                D3DXMatrixIdentity(&matView);
//创建一个单位矩阵
                pD3DDevice->SetTransform(D3DTS_VIEW, &matView); //设置视图变化矩阵

                pCurTarget=target;
        }

        pD3DDevice->BeginScene(); //
开始场景
        pVB->Lock( 0, 0, (BYTE**)&VertArray, 0 ); //锁定顶点数

        return true;
}

 

 

 类似资料:

相关阅读

相关文章

相关问答