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

            永遠(yuǎn)也不完美的程序

            不斷學(xué)習(xí),不斷實(shí)踐,不斷的重構(gòu)……

            常用鏈接

            統(tǒng)計(jì)

            積分與排名

            好友鏈接

            最新評(píng)論

            gles2開發(fā)中遇到的問題及解決方法

            1.紋理
            在gles2中,紋理在glsl中定義的順序,并不是按先后順序來排列的。
            例如以下代碼:
            1uniform sampler2D Samp0;
            2uniform sampler2D Samp1;     
            3uniform sampler2D Samp2;     
            假如我們以為Samp0是第0個(gè)紋理,Samp1是第1個(gè)紋理……這樣就錯(cuò)了。
            這里我們要顯式的指定每個(gè)Sampler的索引。
            下面是取得紋理索引的代碼:
             1for (GLint i = 0; i < nConstantNum; ++i)
             2{
             3    glGetActiveUniform(m_uiProgramObject, i, 256&constant.nLength, &constant.nSize, &constant.glType, constant.szConstantName);
             4    constant.nLocation = glGetUniformLocation(m_uiProgramObject, constant.szConstantName);
             5    constant.nUseType = GPUParameters::GetAutoConstantTypeByName((const char*)constant.szConstantName);
             6
             7        if (constant.glType == GL_SAMPLER_2D || constant.glType == GL_SAMPLER_CUBE)
             8        {
             9            //如果是紋理
            10            s32 nUnitIndex = pPixelShader->GetSamplerIndex(constant.szConstantName);   //獲得配置好的紋理的索引
            11            if (nUnitIndex >= 0)
            12            {
            13                m_mapSamplers.insert(std::make_pair(constant.nLocation, nUnitIndex));
            14            }

            15            else
            16            {
            17                m_mapSamplers.insert(std::make_pair(constant.nLocation, 0));
            18            }

            19        }

            20        else
            21        {
            22                //這里處理其他constant變量
            23        }

            24        
            25}


            然后在調(diào)用該shader前,要開啟紋理索引
            1for (AIRMap<s32, s32>::iterator it = m_mapSamplers.begin(); it != m_mapSamplers.end(); ++it)
            2{
            3 s32 nIndex = it->second;
            4 glUniform1i(it->first, nIndex);
            5}
            這樣才能使設(shè)置的紋理生效。

            2.頂點(diǎn)定義
            在DX下,頂點(diǎn)聲明假如用了position,normal,uv,color,即使shade中其中一項(xiàng)沒用到,只要在C++下把正確的長(zhǎng)度傳進(jìn)去,這樣渲染就會(huì)正常。
            但glsl下,假如其中一項(xiàng)attribute沒用到,會(huì)被過濾掉的,的以C++上傳遞的vertexbuffer的排列方式,必須要嚴(yán)格按照glsl里真正用到的attribute。
            舉個(gè)例子:
            attribute mediump vec3 position;
            attribute mediump vec3 normal;
            attribute mediump vec4 inColor;
            attribute mediump vec2 uvCoords;
            C++如下定義:

             

            1typedef struct tagVertexNormal 
            2{
            3
            4    Vector3Df vPos;
            5    Vector3Df normal;
            6    CColorValue  color;
            7    f32   tu, tv;
            8}
            VERTEX_NORMAL, *LPVERTEX_NORMAL;

            假如glsl代碼里的inColor沒用到,那么按上面的傳遞將會(huì)發(fā)和錯(cuò)誤。
            要使正常運(yùn)行,必須把CColorValue color這行去掉。

            3.紋理采樣要區(qū)分紋理是否含有mipmap
            假如紋理沒有mipmap,GL_NEAREST_MIPMAP_NEAREST這類的統(tǒng)一不能用作采樣。

            4.頂點(diǎn)屬性的綁定必須在VB的更改后。
            如下代碼:
                LPRHWVERTEX pVertex = (LPRHWVERTEX)m_pScreenQuad->m_pVB->Lock();

                //左上角
                pVertex[0].color = color;
                pVertex[0].rhw = 1.0f;
                pVertex[0].tu = 0.0f;
                pVertex[0].tv = 0.0f;
                pVertex[0].x = rectScreen.left - fOffset;
                pVertex[0].y = rectScreen.top - fOffset;
                pVertex[0].z = 1.0f;

                //右上角
                pVertex[1].color = color;
                pVertex[1].rhw = 1.0f;
                pVertex[1].tu = fUVScale;
                pVertex[1].tv = 0.0f;
                pVertex[1].x = rectScreen.right - fOffset;
                pVertex[1].y = rectScreen.top - fOffset;
                pVertex[1].z = 1.0f;

                //右下角
                pVertex[2].color = color;
                pVertex[2].rhw = 1.0f;
                pVertex[2].tu = fUVScale;
                pVertex[2].tv = fUVScale;
                pVertex[2].x = rectScreen.right - fOffset;
                pVertex[2].y = rectScreen.bottom - fOffset;
                pVertex[2].z = 1.0f;

                //左下角
                pVertex[3].color = color;
                pVertex[3].rhw = 1.0f;
                pVertex[3].tu = 0.0f;
                pVertex[3].tv = fUVScale;
                pVertex[3].x = rectScreen.left - fOffset;
                pVertex[3].y = rectScreen.bottom - fOffset;
                pVertex[3].z = 1.0f;
                m_pScreenQuad->m_pVB->Unlock();

                while (!elemLst.IsEnd())
                {
                    if (i >= m_vtGPUAttributes.size())
                    {
                        break;
                    }
                    GLAttributeInfo& attribInfo = m_vtGPUAttributes[i];
                    GLint location = attribInfo.nLocation;
                    const VERTEX_ELEMENT& elem = elemLst.GetNext();
                    size_t typeSize = CVertexDeclaration::GetTypeSize(elem.m_eType);
                    pBufferData = (char*)NULL + elem.m_nOffset;
                    GLenum glType = OpenGLES2Mapping::GetGLType(elem.m_eType);
                    int subUnitCount = typeSize / 4;

                    glEnableVertexAttribArray(location);
                    //GL_Check_Error( "OpenGLES2ShaderObject::Apply - glEnableVertexAttribArray" );
                    glVertexAttribPointer(location, subUnitCount, glType, GL_FALSE, pVertexDeclaration->GetStride(), pBufferData);
                    //GL_Check_Error( "OpenGLES2ShaderObject::Apply - glVertexAttribPointer" );
                    glBindAttribLocation( m_uiProgramObject, location, attribInfo.szAttribName );
                    //GL_Check_Error( "OpenGLES2ShaderObject::Apply - glBindAttribLocation" );
                    pGLES2Renderer->AddVertexAttribValue(location);

                    //PrintDebugString( "Enable and bind vertext attrib [%s] at [%d]\n", attribInfo.szAttribName, location );
                    ++i;
                }
            這里是先寫頂點(diǎn),再綁定頂點(diǎn)聲明,如果順序不對(duì),就會(huì)在DrawXXX的時(shí)候崩。具體原因未明。

            posted on 2014-02-20 19:33 狂爛球 閱讀(2459) 評(píng)論(1)  編輯 收藏 引用 所屬分類: 圖形編程

            評(píng)論

            # re: gles2開發(fā)中遇到的問題及解決方法[未登錄] 2014-04-25 23:38 zy

            去看看最新的4U tech1.8  回復(fù)  更多評(píng)論   

            久久亚洲日韩精品一区二区三区| 久久久久久精品免费免费自慰| 99久久人妻无码精品系列蜜桃| 久久亚洲AV成人出白浆无码国产 | 伊人色综合久久| 国产成人精品综合久久久| 无码乱码观看精品久久| 久久香蕉超碰97国产精品 | 久久国产乱子伦精品免费午夜| 女人高潮久久久叫人喷水| 久久人人爽爽爽人久久久| 久久精品无码一区二区三区免费| 久久久精品国产免大香伊| 办公室久久精品| 久久精品国产清高在天天线| 久久人人爽人人爽AV片| 精品免费tv久久久久久久| 精品一二三区久久aaa片| 久久精品国产一区二区| 97久久香蕉国产线看观看| 91麻豆国产精品91久久久| 国产精品欧美亚洲韩国日本久久 | 无码精品久久久久久人妻中字| 国产亚洲精久久久久久无码AV| 蜜臀av性久久久久蜜臀aⅴ麻豆 | 久久一日本道色综合久久| 久久久久亚洲AV成人网人人网站| 久久精品国产影库免费看| 久久久久亚洲av无码专区导航| 久久久久久综合网天天| 四虎久久影院| 国产精品久久久久久久久软件| 久久无码精品一区二区三区| 国产ww久久久久久久久久| 久久中文娱乐网| 国产99久久久国产精免费| 久久久久一区二区三区| 国产精品无码久久久久| 久久久精品国产Sm最大网站| 久久精品无码免费不卡| 人妻无码精品久久亚瑟影视 |