Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sivansh11 opened this issue Aug 16, 2023 · 9 comments
Open

Comments

@sivansh11
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

sivansh11 commented Aug 22, 2023

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
Copy link
Owner

smasherprog commented Aug 22, 2023

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

@smasherprog
Copy link
Owner

If you find a bug please post a PR

@sivansh11
Copy link
Author

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
Copy link

sharimken commented Oct 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants