Ejemplo n.º 1
0
	void PhongShader::enable( unsigned char lightMask, bool useTexture )
	{
		// Computes the identifier of the shader
		unsigned int identifier = computeIdentifier(lightMask, useTexture);
		// Retrieves the shader
		auto it=m_precompiledShaders.find(identifier) ;
		if(it!=m_precompiledShaders.end()) 
		{ 
			it->second->enable() ; 
			return ;
		}
		// The shader has not been compiled... Let's go!
		ShaderProgram * program = compileShaderProgram(lightMask, useTexture );
		m_precompiledShaders[identifier] = program ;
		program->enable() ;
	}
    void AtomRenderableManager::render(Ambrosia::RenderPass renderPass)
    {
//              qDebug() << "AtomRenderableManager::render";
        if (!validBuffers)
            rebuildBuffers();

        switch (renderPass) {
        case Ambrosia::SHADOW_MAP_PASS:
        case Ambrosia::STENCIL_PASS:
        case Ambrosia::DRAW_OUTLINE_PASS:
            // set shaders
            if (specularShader) specularShader->disable();
            break;
        case Ambrosia::DEPTH_SHADE_PASS:
        case Ambrosia::DEPTH_TRANSPARENT_PASS:
        case Ambrosia::DRAW_SHADE_PASS:
        case Ambrosia::DRAW_TRANSPARENT_PASS:
        case Ambrosia::DRAW_PASS:
        case Ambrosia::NAME_PASS:
            // set shaders
            if (specularShader) specularShader->enable();
            break;
        default:
            break;
        }

        if (renderPass == Ambrosia::DRAW_OUTLINE_PASS || renderPass == Ambrosia::STENCIL_PASS || renderPass == Ambrosia::SHADOW_MAP_PASS) {
            map< Utopia::Node *, AtomRenderable * >::iterator atom_iter = renderables.begin();
            map< Utopia::Node *, AtomRenderable * >::iterator atom_end = renderables.end();
            for(; atom_iter != atom_end; ++atom_iter) {
                AtomRenderable * atom = atom_iter->second;
                if (atom->hasTag(Ambrosia::OUTLINE))
                    atom->render(renderPass);
            }
        } else if (renderPass == Ambrosia::NAME_PASS) {
            map< Utopia::Node *, AtomRenderable * >::iterator atom_iter = renderables.begin();
            map< Utopia::Node *, AtomRenderable * >::iterator atom_end = renderables.end();
            for(; atom_iter != atom_end; ++atom_iter) {
                AtomRenderable * atom = atom_iter->second;
                if (atom->hasTag(Ambrosia::SOLID) || atom->hasTag(Ambrosia::OUTLINE))
                    atom->render(renderPass);
            }
        } else {
            map< unsigned int, map< unsigned int, map< unsigned int, BufferManager * > > >::iterator format_iter = bufferManagers.begin();
            map< unsigned int, map< unsigned int, map< unsigned int, BufferManager * > > >::iterator format_end = bufferManagers.end();
            for (; format_iter != format_end; ++format_iter) {
                map< unsigned int, map< unsigned int, BufferManager * > >::iterator tag_iter = format_iter->second.begin();
                map< unsigned int, map< unsigned int, BufferManager * > >::iterator tag_end = format_iter->second.end();
                for (; tag_iter != tag_end; ++tag_iter) {
                    if ((renderPass == Ambrosia::SHADOW_MAP_PASS || renderPass == Ambrosia::DRAW_PASS)
                        && (tag_iter->first != Ambrosia::SOLID) && (tag_iter->first != Ambrosia::OUTLINE))
                        continue;
                    if ((renderPass == Ambrosia::STENCIL_PASS || renderPass == Ambrosia::DRAW_OUTLINE_PASS || renderPass == Ambrosia::NAME_PASS)
                        && (tag_iter->first != Ambrosia::SOLID && tag_iter->first != Ambrosia::SHADE) && (tag_iter->first != Ambrosia::OUTLINE))
                        continue;
                    if ((renderPass == Ambrosia::DEPTH_SHADE_PASS || renderPass == Ambrosia::DRAW_SHADE_PASS)
                        && (tag_iter->first != Ambrosia::SHADE) && (tag_iter->first != Ambrosia::OUTLINE))
                        continue;
                    if ((renderPass == Ambrosia::DEPTH_TRANSPARENT_PASS || renderPass == Ambrosia::DRAW_TRANSPARENT_PASS)
                        && (tag_iter->first != Ambrosia::Am_TRANSPARENT) && (tag_iter->first != Ambrosia::OUTLINE))
                        continue;
                    map< unsigned int, BufferManager * >::iterator mode_iter = tag_iter->second.begin();
                    map< unsigned int, BufferManager * >::iterator mode_end = tag_iter->second.end();
                    for (; mode_iter != mode_end; ++mode_iter) {
                        unsigned int mode = mode_iter->first;
                        BufferManager * bufferManager = mode_iter->second;
                        bufferManager->render(mode);
                    }
                }
            }
        }

        // disable shaders
        if (specularShader) specularShader->disable();
    }