COpenGLShaderMaterialRenderer bug

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
loverlinfish
Posts: 7
Joined: Thu Aug 06, 2009 8:38 am

COpenGLShaderMaterialRenderer bug

Post by loverlinfish »

Code: Select all

void COpenGLShaderMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
            bool resetAllRenderstates, IMaterialRendererServices* services)
        {
            if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
            {
                if (VertexShader)
                {
                    // set new vertex shader
        #ifdef GL_ARB_vertex_program
                    Driver->extGlBindProgram(GL_VERTEX_PROGRAM_ARB, VertexShader);
                    glEnable(GL_VERTEX_PROGRAM_ARB);
        #elif defined(GL_NV_vertex_program)
                    Driver->extGlBindProgram(GL_VERTEX_PROGRAM_NV, VertexShader);
                    glEnable(GL_VERTEX_PROGRAM_NV);
        #endif
                }
 
                // set new pixel shader
                if (PixelShader[0])
                {
                    GLuint nextShader=PixelShader[0];
                    if (material.FogEnable)
                    {
                        GLint curFogMode;
                        glGetIntegerv(GL_FOG_MODE, &curFogMode);
        //              if (Driver->LinearFog && PixelShader[1])
                        if (curFogMode==GL_LINEAR && PixelShader[1])
                            nextShader=PixelShader[1];
        //              else if (!Driver->LinearFog && PixelShader[2])
                        else if (curFogMode==GL_EXP && PixelShader[2])
                            nextShader=PixelShader[2];
                        else if (curFogMode==GL_EXP2 && PixelShader[3])
                            nextShader=PixelShader[3];
                    }
        #ifdef GL_ARB_fragment_program
                    Driver->extGlBindProgram(GL_FRAGMENT_PROGRAM_ARB, nextShader);
                    glEnable(GL_FRAGMENT_PROGRAM_ARB);
        #elif defined(GL_NV_fragment_program)
                    Driver->extGlBindProgram(GL_FRAGMENT_PROGRAM_NV, nextShader);
                    glEnable(GL_FRAGMENT_PROGRAM_NV);
        #endif
                }
 
                if (BaseMaterial)
                    BaseMaterial->OnSetMaterial(material, material, true, services);
            }
 
            //let callback know used material
            if (CallBack)
                CallBack->OnSetMaterial(material);
 
            for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
                Driver->setActiveTexture(i, material.getTexture(i));
            Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
        }
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Will destroy the the "BaseMaterial-> OnSetMaterial" and the "CallBack-> OnSetMaterial" setting.


when call addHighLevelShaderMaterial(_vs.c_str(), "vertexMain", video::EVST_VS_3_0, _ps.c_str(), "pixelMain", video::EPST_PS_3_0, cb, EMT_TRANSPARENT_ALPHA_CHANNEL);

BaseMaterial->OnSetMaterial(material, material, true, services) will call glEnable(GL_BLEND).
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates) will call glDisable(GL_BLEND).
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: COpenGLShaderMaterialRenderer bug

Post by Nadro »

In trunk we improved shaders handling system in OpenGL.

PS. GL_BLEND will be not disable if you will set BlendOperation to something other than EBO_NONE.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Post Reply