如何在 DirectX 10 中绘制大量 (500+) 精灵来构建等距平铺地图?

发布于 2024-11-10 13:36:45 字数 1428 浏览 4 评论 0原文

因此,我一直在阅读一些有关 DirectX 的书籍(具体来说是 10 本书),并尝试构建一个使用它的游戏,但我被一个问题所困扰,这些书似乎都没有提到:我'我用精灵构建等距地图,随着棋盘变大,程序速度急剧减慢。每个图块都是 64x45,当我用精灵构建 36x19 (684) 图块地图时,我的应用程序加载大约需要 6 秒,每帧之间大约需要 5 秒。由于使用断点进行调试没有产生任何好的线索,因此我已经缩小了当前代码中问题所在的区域:

任何帮助将不胜感激。

    const FLOAT clearcolor[4] = {0.0f, 0.0f, 0.0f, 0.0f}; 
    pD3DDevice->ClearRenderTargetView(pRenderTargetView, clearcolor);
    if(spriteObject != NULL){
        spriteObject->Begin(D3DX10_SPRITE_SORT_TEXTURE);        
        pD3DDevice->OMGetBlendState(&pOriginalBlendState10, OriginalBlendFactor, &OriginalSampleMask);
        if(pBlendState10)
        {
            FLOAT NewBlendFactor[4] = {0,0,0,0};
            pD3DDevice->OMSetBlendState(pBlendState10, NewBlendFactor,0xffffffff);
        }
        D3DXMatrixScaling(&matScale, 64, 45, 1.0f);

        for(int y = 0;y < 36;y++){
            px=0;
            if(y % 2 == 1)
                px-=32;
            for(int x = 0;x < 19;x++){  
                D3DXMatrixTranslation(&matTrans, px, viewport.Height - py, 0.1f);
                testTile.matWorld = (matScale * matTrans);
                spriteObject->DrawSpritesImmediate(&testTile, 1, 0, 0);
                px+=64;
            }
            py+=23;
        }
        spriteObject->End();
        pD3DDevice->OMSetBlendState(pOriginalBlendState10, OriginalBlendFactor, OriginalSampleMask);

So, I've been puttering around with a few books on DirectX (specifically 10) and am trying my hand at building a game that uses it, but I'm stumped by a problem that none of the books seem to mention: I'm building an isometric map with sprites and as the board gets larger, the program slows down dramatically. Each tile is 64x45 and by the time that I have constructed a 36x19 (684) tile map with sprites, it takes roughly 6 seconds for my application to load up and about 5 seconds between each frame. Since debugging with breakpoints hasn't yielded any good clues I've narrowed down the area in my current code where the problem is to this specific section:

Any help would be appreciated.

    const FLOAT clearcolor[4] = {0.0f, 0.0f, 0.0f, 0.0f}; 
    pD3DDevice->ClearRenderTargetView(pRenderTargetView, clearcolor);
    if(spriteObject != NULL){
        spriteObject->Begin(D3DX10_SPRITE_SORT_TEXTURE);        
        pD3DDevice->OMGetBlendState(&pOriginalBlendState10, OriginalBlendFactor, &OriginalSampleMask);
        if(pBlendState10)
        {
            FLOAT NewBlendFactor[4] = {0,0,0,0};
            pD3DDevice->OMSetBlendState(pBlendState10, NewBlendFactor,0xffffffff);
        }
        D3DXMatrixScaling(&matScale, 64, 45, 1.0f);

        for(int y = 0;y < 36;y++){
            px=0;
            if(y % 2 == 1)
                px-=32;
            for(int x = 0;x < 19;x++){  
                D3DXMatrixTranslation(&matTrans, px, viewport.Height - py, 0.1f);
                testTile.matWorld = (matScale * matTrans);
                spriteObject->DrawSpritesImmediate(&testTile, 1, 0, 0);
                px+=64;
            }
            py+=23;
        }
        spriteObject->End();
        pD3DDevice->OMSetBlendState(pOriginalBlendState10, OriginalBlendFactor, OriginalSampleMask);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

a√萤火虫的光℡ 2024-11-17 13:36:45

DrawSpritesImmediate 的全部意义在于,您希望使用数百或数千个精灵的数组来调用它......而不是一次一个精灵。

或者,尝试将“立即”调用更改为使用 DrawSpritesBuffered,后跟 ID3DX10Sprite::Flush(在循环外部,就在 End() 之前)。

但即使如此...... 5s/帧听起来非常慢......你确定你没有使用软件“参考光栅化器”而不是硬件?

The whole point of DrawSpritesImmediate is that you want to call it with an array of hundreds or thousands of sprites... not one sprite at a time.

Alternatively, try changing your "Immediate" call to using DrawSpritesBuffered, followed by a ID3DX10Sprite::Flush (outside the loops, just before the End()).

But even with that... 5s/frame sounds awfully slow... are you sure you're not using the software "reference rasterizer" instead of the HW ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文