Search code examples
rustsdl-2

Is RenderCopyEx with default parameters more resource intensive than RenderCopy in SDL2?


I am writing a personal game framework in rust using sdl2 bindings from rust-sdl2. I want to write a fill_text function, I use a builder pattern to create arguments, such as text, position and rotateion. If no scale, rotation, flipping, etc... parameters are not specified, i can use the normal copy_f function, but if not, i have to use copy_ex_f.

Now, I want to ask, does it make sense to do something like this?:

   if angle != 0.0 || center.is_some() || scale != 1.0 || flip_horizontal || flip_vertical {
        self.canvas
            .copy_ex_f(
                &texture,
                None,
                sdl2::rect::FRect::new(x, y, query.width as f32, query.height as f32),
                angle as f64,
                center.map(|(x, y)| sdl2::rect::FPoint::new(x, y)),
                flip_horizontal,
                flip_vertical,
            )
            .unwrap();
    } else {
        self.canvas
            .copy_f(
                &texture,
                None,
                sdl2::rect::FRect::new(x, y, query.width as f32, query.height as f32),
            )
            .unwrap();
    }

is the copy_f function lighter to execute?


Solution

  • No, because this check is already performed inside the SDL_RenderCopyExF function. See here for reference.

    So in fact by redundantly performing the check yourself, the program is now probably a tiny bit less performant.