smasherprog / screen_capture_lite

cross platform screen/window capturing library
MIT License
616 stars 156 forks source link

Are there any plans to re-integrate screen capture lite to unity ? #158

Open sivansh11 opened 10 months ago

sivansh11 commented 10 months ago

I tried using screen capture lite with vulkan (as a demo) and it worked well, I wanna use this in unity, but the example folder for unity is empty, are there any plans for integrating (or re-integrating) it with unity ?

smasherprog commented 10 months ago

I need a good integration to unity as I dont use unity. There was a previous PR, but I felt it needed more work to make it generic and clean.

sivansh11 commented 10 months ago

Thats okay, Ill look into it (I also dont really use unity atall, but need to for a project)

Btw, do you have any tip for making it faster for displaying the screen captured window in a 3d environment ? In the openGL example there are multiple "copies", first is the cpu to cpu copy (in ExtractAndConvertToRGBA) and the second is cpu to gpu copy (glTexSubImage2D), is it possible for me to directly from the underlying operating system to the GPU ?

smasherprog commented 10 months ago

To my knowledge, there isnt a more efficient method. The data needs to be copied INTO a gltex. If the data is perfectly alligned you can probably do a single copy directly into the gl texture. There are issues of synchonization that i did not cover on the example, because you could be Displaying the image, but also writing to the underlying buffer at the same time. So, the problem is fun one for sure!

sivansh11 commented 10 months ago

hey, sorry for the constant messaging, I just noticed (I should have earlier) that there are cSharp bindings, are they stable like the c++ version ? also do you guys have a discord I could join ?

sivansh11 commented 10 months ago

how do I actually get the image data in the c# example ? the bitmap stuff is commented out, uncommenting it doesnt work (BitMap not found) how do I get and copy the data into a local buffer ? do I need to use SCL_Utility_CopyToContiguous

smasherprog commented 10 months ago

Just pulled down master at my work, built and ran it without issue. Everything works as expected, uncomment out the bitmap stuff.

smasherprog commented 10 months ago

If you find a bug please post a PR

sivansh11 commented 10 months ago

I am actually really new to c# (for unity), so I donno if I am doing something wrong or if the c# bindings are incomplete, can you make an example where getting the image data is shown my goal atm is to be able to upload the data to a texture in unity

the c++ examples are really good and easy to follow from the c++ example, there is a clear way to copy the data to a local buffer

static void ExtractAndConvertToRGBA(const SL::Screen_Capture::Image &img, uint8_t *dst, size_t dst_size) {
    assert(dst_size >= static_cast<size_t>(SL::Screen_Capture::Width(img) * SL::Screen_Capture::Height(img) * sizeof(SL::Screen_Capture::ImageBGRA)));
    auto imgsrc = StartSrc(img);
    auto imgdist = dst;
    for (auto h = 0; h < Height(img); h++) {
        auto startimgsrc = imgsrc;
        for (auto w = 0; w < Width(img); w++) {
            *imgdist++ = imgsrc->R;
            *imgdist++ = imgsrc->G;
            *imgdist++ = imgsrc->B;
            *imgdist++ = 1;
            imgsrc++;
        }
        imgsrc = SL::Screen_Capture::GotoNextRow(img, startimgsrc);
    }
}

there is no way to get the imageSrc and GotoNextRow in the C# bindings, at least its not immediately obvious to me how I would achieve such a thing

sharimken commented 8 months ago

I am actually really new to c# (for unity), so I donno if I am doing something wrong or if the c# bindings are incomplete, can you make an example where getting the image data is shown my goal atm is to be able to upload the data to a texture in unity

the c++ examples are really good and easy to follow from the c++ example, there is a clear way to copy the data to a local buffer

static void ExtractAndConvertToRGBA(const SL::Screen_Capture::Image &img, uint8_t *dst, size_t dst_size) {
    assert(dst_size >= static_cast<size_t>(SL::Screen_Capture::Width(img) * SL::Screen_Capture::Height(img) * sizeof(SL::Screen_Capture::ImageBGRA)));
    auto imgsrc = StartSrc(img);
    auto imgdist = dst;
  for (auto h = 0; h < Height(img); h++) {
      auto startimgsrc = imgsrc;
      for (auto w = 0; w < Width(img); w++) {
          *imgdist++ = imgsrc->R;
          *imgdist++ = imgsrc->G;
          *imgdist++ = imgsrc->B;
          *imgdist++ = 1;
          imgsrc++;
      }
      imgsrc = SL::Screen_Capture::GotoNextRow(img, startimgsrc);
  }
}

there is no way to get the imageSrc and GotoNextRow in the C# bindings, at least its not immediately obvious to me how I would achieve such a thing

I've been integrated it into Unity3D successfully, but this does take me at least 3~6 months of work. Calling the function and grabbing few frames is not too difficult, but you will have to spend another few months to optimise the performance, memory leak..etc. If budget is allowed, better have a look on Unity Asset Store with relevant keywords.