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

            我參與的團隊

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 370201
            • 排名 - 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) 閱讀(3851) 評論(1)  編輯 收藏 引用 所屬分類: 3D引擎開發

            Feedback

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

            一级女性全黄久久生活片免费 | 亚洲国产精品无码久久一线 | 秋霞久久国产精品电影院| 久久亚洲AV无码精品色午夜| 99久久综合国产精品二区| 国产成人久久精品激情| 久久夜色精品国产欧美乱| 久久久精品人妻一区二区三区蜜桃| 久久综合伊人77777| 色婷婷噜噜久久国产精品12p| 一级做a爱片久久毛片| 国产精品欧美亚洲韩国日本久久| 久久精品国产免费| 91精品日韩人妻无码久久不卡| 国产精品久久久久影院色 | 久久免费视频观看| 伊人久久综合热线大杳蕉下载| 99久久亚洲综合精品网站| 国产精品成人无码久久久久久| 精品免费久久久久国产一区 | 亚洲午夜久久久久妓女影院| 中文精品久久久久人妻| 久久热这里只有精品在线观看| 亚洲欧洲日产国码无码久久99| 色欲av伊人久久大香线蕉影院| 国产精品岛国久久久久| 久久久国产精品| 亚洲国产美女精品久久久久∴| 99久久er这里只有精品18| 青青青青久久精品国产| 一本一本久久a久久精品综合麻豆| 综合人妻久久一区二区精品| 97久久超碰国产精品旧版| 久久国产精品国语对白| 国色天香久久久久久久小说| 精品久久久久久| 麻豆av久久av盛宴av| 曰曰摸天天摸人人看久久久| 日韩精品久久久久久久电影| 99久久99久久| 亚洲人成精品久久久久|