• <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)

            我參與的團隊

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 371288
            • 排名 - 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模板類  回復  更多評論
              

            久久精品国产亚洲av影院| 香港aa三级久久三级| 亚洲午夜精品久久久久久app| 久久综合精品国产一区二区三区| 国产精品久久久久久久久久影院 | 久久中文字幕人妻熟av女| 一本久久a久久精品综合香蕉 | 99久久精品国产一区二区三区| 国内精品久久久久久麻豆| 久久久久国产精品嫩草影院| 91精品国产乱码久久久久久| 日日狠狠久久偷偷色综合96蜜桃| 亚洲成色www久久网站夜月| 国内精品久久久久久久影视麻豆| 中文字幕无码免费久久| 久久久久亚洲爆乳少妇无| 久久亚洲AV成人无码国产 | 青青热久久国产久精品 | 久久伊人五月天论坛| 91精品国产综合久久久久久| 久久久亚洲欧洲日产国码是AV | 久久久久久久久无码精品亚洲日韩| 久久黄视频| 国产精品美女久久久免费| 成人妇女免费播放久久久| 久久精品国产亚洲AV蜜臀色欲 | 一级A毛片免费观看久久精品| 久久精品人人做人人爽电影| 久久香蕉超碰97国产精品| 国产精品一区二区久久精品涩爱| 久久国产免费直播| 99久久精品国产一区二区三区| 久久精品国产91久久综合麻豆自制 | 国产精品久久久久久久久| 狠狠色丁香久久婷婷综合| 欧美性大战久久久久久| 欧美成a人片免费看久久| 久久激情五月丁香伊人| 久久综合久久鬼色| 久久性精品| 国内精品综合久久久40p|