void RenderManager::AddTerrainToRenderer(TerrainManager &t)
{
	terrain = SetupVAO(t.GetTerrainMesh());
	terrainSize = t.GetTerrainMesh().GetSize();
	terrainManager = &t;
	water = SetupVAO(t.GetWaterMesh());
}
bool RenderManager::AddToRenderer(Mesh &m)
//  Adds specified mesh to the render list
//  If the mesh is brand new it will import the texture and compile the
//  display list needed to draw the mesh, if the mesh or texture has been
//  Used before they will not be reimported/compiled and we will instead use
//  the old versions
{
	std::string meshModel = m.GetMeshSourceFilePath();

	//  Only bother compiling a new Display List if one doesn't already exist for this object
	if (!VAOMap.count(m.GetUniqueID())) {
		if (meshModel.length() > 0) {
			if (!MeshFileMap.count(meshModel)) {
				//  Compile the object's Display List and remember that this object has been compiled to save repetition
				MeshFileMap[meshModel] = SetupVAO(m);
			}
			VAOMap[m.GetUniqueID()] = MeshFileMap[meshModel];
		} else {
			VAOMap[m.GetUniqueID()] = SetupVAO(m);
		}
	}

	//  Add our new (or repeated) item to the render list
	if(m.IsTransparent()) {
		renderList.push_back(m.GetUniqueID());
	} else {
		opaqueRenderList.push_back(m.GetUniqueID());
	}
//	m.DeleteVertexData();
	return true;
}
Beispiel #3
0
void Canvas::DrawRenderTexture() {
	if( !m_render_texture ) {
		return;
	}

	if( !non_legacy_supported ) {
		// Matrix mode is currently GL_TEXTURE as set by Renderer.
		// We get ready for a surprise from SFML...
		CheckGLError( glPushMatrix() );
		sf::Texture::bind( &( m_render_texture->getTexture() ) );

		if( !m_display_list ) {
			m_display_list = glGenLists( 1 );

			if( !m_display_list ) {
#if defined( SFGUI_DEBUG )
				std::cerr << "SFGUI warning: Canvas failed to create OpenGL display list.\n";
#endif
			}

			CheckGLError( glNewList( m_display_list, GL_COMPILE ) );

			// Pop the texture matrix that SFML secretly loaded behind our backs...
			CheckGLError( glMatrixMode( GL_TEXTURE ) );
			CheckGLError( glPopMatrix() );

			CheckGLError( glColor3ub( 255, 255, 255 ) );

			// Oh the horror... not.
			CheckGLError( glMatrixMode( GL_MODELVIEW ) );
			CheckGLError( glPushMatrix() );
			CheckGLError( glLoadIdentity() );
			CheckGLError( glMatrixMode( GL_PROJECTION ) );
			CheckGLError( glPushMatrix() );
			CheckGLError( glLoadIdentity() );
			CheckGLError( glBegin( GL_QUADS ) );
			CheckGLError( glTexCoord2s( 0, 0 ) );
			CheckGLError( glVertex2s( -1, -1 ) );
			CheckGLError( glTexCoord2s( 1, 0 ) );
			CheckGLError( glVertex2s( 1, -1 ) );
			CheckGLError( glTexCoord2s( 1, 1 ) );
			CheckGLError( glVertex2s( 1, 1 ) );
			CheckGLError( glTexCoord2s( 0, 1 ) );
			CheckGLError( glVertex2s( -1, 1 ) );
			CheckGLError( glEnd() );
			CheckGLError( glPopMatrix() );
			CheckGLError( glMatrixMode( GL_MODELVIEW ) );
			CheckGLError( glPopMatrix() );
			CheckGLError( glMatrixMode( GL_TEXTURE ) );

			CheckGLError( glEndList() );
		}

		CheckGLError( glCallList( m_display_list ) );
	}
	else {
		// Non-Legacy
		if( !m_shader ) {
			SetupShader();
		}

		if( !non_legacy_supported ) {
			// Fall back to legacy starting in this frame.
			DrawRenderTexture();
			return;
		}

		if( !m_vbo ) {
			SetupVBO();
		}

		auto is_vertex_array = CheckGLError( GLEXT_glIsVertexArray( m_vao ) );

		if( !is_vertex_array ) {
			SetupVAO();
		}

		struct Texture : sf::GlResource {
			sf::Vector2u unused1;
			sf::Vector2u unused2;
			unsigned int unused3;
			bool unused4;
			bool unused5;
			mutable bool pixels_flipped;
			sf::Uint64 unused6;
		};

		// Just so that SFML doesn't mess with the texture matrix.
		const_cast<Texture*>( reinterpret_cast<const Texture*>( &( m_render_texture->getTexture() ) ) )->pixels_flipped = false;

		sf::Shader::bind( m_shader.get() );

		CheckGLError( GLEXT_glBindVertexArray( m_vao ) );

		CheckGLError( glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 ) );

		CheckGLError( GLEXT_glBindVertexArray( 0 ) );

		sf::Shader::bind( nullptr );
	}
}
void RenderManager::AddSkyBox(Mesh &m)
{
	skyBox = SetupVAO(m);
	sky = m.GetUniqueID();
}