0

I want to invoke threads on these member functions (they take the exact same parameters). Note that this ALL takes place inside a class called Renderer.


    template <class Pixel>
    void DrawFlatBottom(Pixel& leftPixel, Vec2& leftScreen, Pixel& topPixel, Vec2& topScreen, Pixel& rightPixel, Vec2& rightScreen, Vec4 (*PixelShader)(Pixel& sd)) {

          // DrawFlatBottom implementation

    }

    template <class Pixel>
    void DrawFlatTop(Pixel& leftPixel, Vec2& leftScreen, Pixel& bottomPixel, Vec2& bottomScreen, Pixel& rightPixel, Vec2& rightScreen, Vec4 (*PixelShader)(Pixel& sd)) {

          // DrawFlatTop implementation 

    }

Here is how I am trying to invoke the threads:

template <class Pixel>
void DrawTriangle(Pixel p1, Pixel p2, Pixel p3, Vec4 (*PixelShader)(Pixel& sd)) {

     std::thread flatBottom(&Renderer::DrawFlatBottom<Pixel>, std::ref(*middlePixel), std::ref(*middleScreen), std::ref(*topPixel), std::ref(*topScreen), std::ref(cutPixel), std::ref(cutScreen), PixelShader);
     std::thread flatTop(&Renderer::DrawFlatTop<Pixel>, std::ref(*middlePixel), std::ref(*middleScreen), std::ref(*bottomPixel), std::ref(*bottomScreen), std::ref(cutPixel), std::ref(cutScreen), PixelShader);

     // rest of DrawTriangle implementation
}

Notice that these invocations are themselves inside a templated function, whose template parameter Pixel is being passed into another templated function (DrawFlatBottom and DrawFlatTop)

However, this causes the compilation errors

Error   C2672   'std::invoke': no matching overloaded function found
Error   C2893   Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'

I think all the parameters I am passing are correct (ie: they are all the correct types). Maybe I am passing the PixelShader function pointer (last parameter) incorrectly. I'm pretty sure it must have something to do with the template.

Joey
  • 102
  • 6
  • You need to pass a renderer too (you can invoke pointer-to-member functions on pointers too, so you can just do `&someRenderer` instead of `std::ref(someRenderer)`) – Artyer May 02 '20 at 00:37
  • Where in the thread constructor do I put that? Can I just use 'this'? – Joey May 02 '20 at 00:42
  • If `DrawTriangle` is a member function of `Renderer`, then that's probably what you want. As the first argument, `std::thread flatBottom(&Renderer::DrawFlatBottom, this, std::ref(*middlePixel), ...);` – Artyer May 02 '20 at 00:43
  • Wow! Thanks so much! You just doubled my frame rate! – Joey May 02 '20 at 00:46

0 Answers0