Jump to content
  • Advertisement
Arjan B

Extremely slow in Debug: Converting between pixel formats for pixels held in std::vector

Recommended Posts

Calling just about any function once-per-pixel is going to be slow as molasses in debug mode because functions are never inlined in debug mode.  Luckily you can bypass all of these expensive function calls by writing directly to memory:

std::vector<sf::Uint8> SfmlFilm::ToRgba(const std::vector<Spectrum>& image)
{
	std::vector<sf::Uint8> rgba(GetWidth() * GetHeight() * 4);
  
	auto p = &rgba[0];
    
	for (auto spectrum : image)
	{
		const auto max = 255;
		*p++ = static_cast<sf::Uint8>(spectrum.r * max);
		*p++ = static_cast<sf::Uint8>(spectrum.g * max);
		*p++ = static_cast<sf::Uint8>(spectrum.b * max);
		*p++ = max;
	}
	return rgba;
}

 

Share this post


Link to post
Share on other sites
Advertisement

Thanks for the help, everybody!

For the ones interested, splitting up the steps shows that it really is in the push(/emplace)_back() calls:

split-profiling.png

Using a light breeze's suggestion, FPS went up from 1 to 95.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!