• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            李錦俊(mybios)的blog

            游戲開發 C++ Cocos2d-x OpenGL DirectX 數學 計算機圖形學 SQL Server

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              86 Posts :: 0 Stories :: 370 Comments :: 0 Trackbacks

            公告

            QQ:30743734
            EMain:mybios@qq.com

            常用鏈接

            留言簿(16)

            我參與的團隊

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 371318
            • 排名 - 67

            最新評論

            閱讀排行榜

            評論排行榜

            昨天提到的我想到了個優化渲染的新方法。。今天花了一個早上終于實現了。5555其實不需要這么久,偏偏是一個小小的BUG花了我兩個小時。馬上進入正題吧。

            原來的GUI渲染系統是每個Window都繼承于RenderCache,每個RenderCache中保存著需要渲染的矩形信息,然后每幀渲染的時候一個個矩形添加到渲染器中再動態修改頂點坐標(一個矩形對應6個頂點)。慢就慢在動態修改頂點!
            今天實現的新方法,就是直接把頂點保存在RenderCache中,然后每幀渲染的時候直接DrawIndexedPrimitiveUP出來,Release版速度從500提升到550FPS了。DEBUG版從130提升到360FPS(主要是stl的東西在debug版下慢許多)。

            貼下RenderCache的代碼

            h文件
            #pragma?once
            #include?
            "GameCorePreReq.h"
            #include?
            "Rect.h"
            #include?
            "ListHelper.h"
            #include?
            "GCVector3.h"
            #include?
            "GCVector2.h"
            #include?
            "GCArray.h"


            #define?GUI_Z?0.0f

            //?四個角的顏色
            struct?BoundsColor
            {
            ????BoundsColor(
            ????????GC3DCOLOR?crTopLeft?,?
            ????????GC3DCOLOR?crTopRight?,?
            ????????GC3DCOLOR?crBottomLeft?,?
            ????????GC3DCOLOR?crBottomRight
            ????????)
            ????????:?m_crTopLeft(crTopLeft)
            ????????,?m_crTopRight(crTopRight)
            ????????,?m_crBottomLeft(crBottomLeft)
            ????????,?m_crBottomRight(crBottomRight)
            ????
            {

            ????}
            ;

            ????BoundsColor(GC3DCOLOR?color)
            ????????:?m_crTopLeft(color)
            ????????,?m_crTopRight(color)
            ????????,?m_crBottomLeft(color)
            ????????,?m_crBottomRight(color)
            ????
            {

            ????}
            ;

            ????BoundsColor(
            const?BoundsColor?&color)
            ????
            {
            ????????
            *this?=?color;
            ????}
            ;

            ????BoundsColor()
            {};

            ????
            void?SetRefAlpha(const?float?&fAlpha)
            ????
            {
            ????????GC3DCOLOR_SETA(m_crTopLeft?,?GC3DCOLOR_GETA(m_crTopLeft)?
            *?fAlpha);
            ????????GC3DCOLOR_SETA(m_crTopRight?,?GC3DCOLOR_GETA(m_crTopRight)?
            *?fAlpha);
            ????????GC3DCOLOR_SETA(m_crBottomLeft?,?GC3DCOLOR_GETA(m_crBottomLeft)?
            *?fAlpha);
            ????????GC3DCOLOR_SETA(m_crBottomRight?,?GC3DCOLOR_GETA(m_crBottomRight)?
            *?fAlpha);
            ????}


            ????
            void?SetAlpha(const?float?&fAlpha)
            ????
            {
            ????????GC3DCOLOR_SETA(m_crTopLeft?,?fAlpha);
            ????????GC3DCOLOR_SETA(m_crTopRight?,?fAlpha);
            ????????GC3DCOLOR_SETA(m_crBottomLeft?,?fAlpha);
            ????????GC3DCOLOR_SETA(m_crBottomRight?,?fAlpha);
            ????}

            ????GC3DCOLOR?m_crTopLeft;
            ????GC3DCOLOR?m_crTopRight;
            ????GC3DCOLOR?m_crBottomLeft;
            ????GC3DCOLOR?m_crBottomRight;

            ????BoundsColor?
            &?operator?=(const?BoundsColor&?color)
            ????
            {
            ????????m_crTopLeft?
            =?color.m_crTopLeft;
            ????????m_crTopRight?
            =?color.m_crTopRight;
            ????????m_crBottomLeft?
            =?color.m_crBottomLeft;
            ????????m_crBottomRight?
            =?color.m_crBottomRight;
            ????????
            return?*this;
            ????}

            }
            ;


            //?一個頂點
            struct?QuadVertex
            {
            ????QuadVertex(f32?x?,?f32?y?,?GC3DCOLOR?color?,?f32?ux?,?f32?uy?,?Texture?
            *pTexture)
            ????????:?m_pos(x?,?y?,?GUI_Z)
            ????????,?m_rhw(
            1)
            ????????,?m_diffuse(color)
            ????????,?m_uv(ux?,?uy)
            ????????,?m_pTexture(pTexture)
            ????
            {

            ????}
            ;
            ????Vector3?m_pos;????????????
            //?頂點的位置
            ????float??m_rhw;????????????????//?始終設置為1
            ????GC3DCOLOR?m_diffuse;????????????//?顏色
            ????Vector2?m_uv;????????????????//?貼圖坐標
            ????Texture*?m_pTexture;????????//?紋理
            }
            ;

            //?需要渲染的隊列的一個方塊
            struct?GUIRenderQuad
            {
            ????GUIRenderQuad(
            const?Rect&?rectDest,?const?BoundsColor&?boundsColor,?Texture*?pTexture,?const?RectFloat?&rectTexture)
            ????????:?m_topLeft(rectDest.left?,?rectDest.top?,?boundsColor.m_crTopLeft?,?rectTexture.left?,?rectTexture.top?,?pTexture)
            ????????,?m_topRight(rectDest.right?,?rectDest.top?,?boundsColor.m_crTopRight?,?rectTexture.right?,?rectTexture.top?,?pTexture)
            ????????,?m_bottomLeft(rectDest.left?,?rectDest.bottom?,?boundsColor.m_crBottomLeft?,?rectTexture.left?,?rectTexture.bottom?,?pTexture)
            ????????,?m_bottomRight(rectDest.right?,?rectDest.bottom?,?boundsColor.m_crBottomRight?,?rectTexture.right?,?rectTexture.bottom?,?pTexture)
            ????
            {

            ????}
            ;
            ????QuadVertex?m_topLeft;
            ????QuadVertex?m_topRight;
            ????QuadVertex?m_bottomLeft;
            ????QuadVertex?m_bottomRight;
            }
            ;

            typedef?Array
            <GUIRenderQuad>?ListGUIRenderQuad;

            class?GAMECORE_EXPORT?GUIRenderCache
            {
            protected:
            ????
            //?不允許顯式創建,只可以繼承
            ????GUIRenderCache(void);
            public:
            ????
            virtual?~GUIRenderCache(void);

            ????
            //?添加到渲染隊列,支持很多版本的重載
            ????void?AddCache(const?Rect&?rectDest,?const?BoundsColor&?boundsColor,?Texture*?pTexture,?const?RectFloat?&rectTexture)
            ????
            {
            ????????AddCache(GUIRenderQuad(rectDest?,?boundsColor?,?pTexture?,?rectTexture));
            ????}
            ;
            ????
            void?AddCache(const?Rect&?rectDest,?const?BoundsColor&?boundsColor,?Texture*?pTexture)
            ????
            {
            ????????AddCache(GUIRenderQuad(rectDest?,?boundsColor?,?pTexture?,?RectFloat(
            0,0,1,1)));
            ????}
            ;
            ????
            void?AddCache(const?Rect&?rectDest,?const?BoundsColor&?boundsColor)
            ????
            {
            ????????AddCache(GUIRenderQuad(rectDest?,?boundsColor?,?
            0?,?RectFloat(0,0,1,1)));
            ????}
            ;
            ????
            void?AddCache(const?GUIRenderQuad?*quadPtr)
            ????
            {
            ????????AddCache(
            *quadPtr);
            ????}

            ????
            void?AddCache(const?GUIRenderQuad&?quad)
            ????
            {
            ????????m_listGUIRenderQuad.push_back(quad);
            ????}

            ????
            //?渲染到隊列
            ????void?RenderCache();
            ????
            //?直接渲染
            ????void?RenderDirect();
            ????
            //?清空cache隊列
            ????void?ClearCacheList(void)
            ????
            {
            ????????m_listGUIRenderQuad.clear();
            ????}


            ????
            void?SetDirty(bool?bDirty){m_bDirty?=?bDirty;};
            ????
            const?bool?IsDirty()?const{return?m_bDirty;};
            protected:

            ????
            void?Cache()
            ????
            {
            ????????
            //?從新Cache隊列
            ????????if(m_bDirty)
            ????????
            {
            ????????????ClearCacheList();
            ????????????DoCache();
            ????????????m_bDirty?
            =?false;
            ????????}

            ????}

            ????
            //?Cache需要渲染的項目
            ????virtual?void?DoCache(){};

            ????ListGUIRenderQuad?m_listGUIRenderQuad;????
            //?渲染隊列
            ????bool?m_bDirty;????????????????????????????//?需要重新Cache需要渲染的項目
            }
            ;


            cpp文件
            #include?"GameCorePreReq.h"
            #include?
            "GUIRenderCache.h"
            #include?
            "Systems.h"
            #include?
            "GUIRendererSystem.h"

            GUIRenderCache::GUIRenderCache(
            void)
            :?m_bDirty(
            true)
            {
            }


            GUIRenderCache::
            ~GUIRenderCache(void)
            {
            }



            //?渲染需要Cache隊列
            void?GUIRenderCache::RenderCache()
            {
            ????Cache();
            ????
            if(m_listGUIRenderQuad.empty())
            ????????
            return;
            ????ListGUIRenderQuad?
            *pQuad?=?&m_listGUIRenderQuad;
            ????Systems::GetSingleton().GetGUIRendererSystem()
            ->PushBack(pQuad);
            }


            void?GUIRenderCache::RenderDirect()
            {
            ????Cache();
            ????
            if(m_listGUIRenderQuad.empty())
            ????????
            return;
            ????Systems::GetSingleton().GetGUIRendererSystem()
            ->RenderDirect(&m_listGUIRenderQuad);
            }
            posted on 2006-12-24 14:14 李錦俊(mybios) 閱讀(3860) 評論(1)  編輯 收藏 引用 所屬分類: 3D引擎開發

            Feedback

            # re: 3D 引擎中的 GUI 渲染優化補完 2006-12-24 20:15 李錦俊
            哦。是了。其中用到的Array是IrrLicht引擎中的irr::core::array模板類  回復  更多評論
              

            国产激情久久久久影院小草| 久久香蕉国产线看观看猫咪?v| 狠狠色丁香久久婷婷综合图片| 亚洲国产成人久久综合区| 亚洲精品NV久久久久久久久久| 久久福利资源国产精品999| 久久久噜噜噜www成人网| 久久99国产精品久久| 精品99久久aaa一级毛片| 成人久久免费网站| 色综合久久中文综合网| 久久只这里是精品66| 97久久综合精品久久久综合| 久久精品女人天堂AV麻| 日韩av无码久久精品免费| 大美女久久久久久j久久| 无码精品久久久久久人妻中字| 久久精品国产一区| 亚洲欧洲久久av| 国产亚洲美女精品久久久久狼| 麻豆久久久9性大片| 久久久久99精品成人片| 91精品国产91久久综合| 久久精品aⅴ无码中文字字幕不卡| 女人香蕉久久**毛片精品| 久久人妻少妇嫩草AV蜜桃| 久久婷婷色综合一区二区| 久久综合狠狠色综合伊人| 乱亲女H秽乱长久久久| 久久婷婷五月综合成人D啪| 老司机午夜网站国内精品久久久久久久久 | 97精品依人久久久大香线蕉97 | 久久久噜噜噜久久中文福利| 亚洲另类欧美综合久久图片区| 大蕉久久伊人中文字幕| 免费国产99久久久香蕉| 久久99国产精品久久| 伊人色综合久久天天| a级毛片无码兔费真人久久| 国产2021久久精品| 久久精品亚洲欧美日韩久久|