예제 #1
0
파일: main.cpp 프로젝트: WendyHanzer/4s
void render(const Planet& planet, Camera& camera, ShaderProgram& program)
{
	static glm::mat4 mvp;
	
	program.use();
	
	/*
	*	shaders have various attributes for vertices
	*	these functions will enable attributes for each vertex
	*	if attributes are not enabled, they can't be accessed by the pipeline
	*/
	glEnableVertexAttribArray(0);
	
	/*
	*	this sets target buffer to current active buffer!
	*	buffers store vertices
	*/
	glBindBuffer(GL_ARRAY_BUFFER, planet.model->vbo_geometry);
	
	//premultiply the matrix for this example
	camera.project(planet.position, mvp);

	//upload the matrix to the shader
	glUniformMatrix4fv(0, 1, GL_FALSE, glm::value_ptr(mvp));

	/*
	*	these calls state how to interpret data inside the buffer
	*/
	//set pointers into the vbo for each of the attributes(position and color)
	//position, texture, color, normal
	glVertexAttribPointer(	0,			//location of attribute
							3,									//number of elements
							GL_FLOAT,							//type
							GL_FALSE,							//normalized?
							sizeof(Vertex),						//stride
							(void*)offsetof(Vertex,position));	//offset

	glDrawArrays(GL_TRIANGLES, 0, planet.model->triangles); //mode, starting index, count
	//broken
	//model.mesh->render(program);
	
	//unload buffer
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	//disable shader program attributes
	glDisableVertexAttribArray(0);
	
	//unload shader program
	program.disable();
}
    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();
    }