convert SharpDXDirect3D11 Texture2D? - Printable Version
+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: Ab3d.DXEngine (https://forum.ab4d.com/forumdisplay.php?fid=11)
+--- Thread: convert SharpDXDirect3D11 Texture2D? (/showthread.php?tid=4111)
convert SharpDXDirect3D11 Texture2D? - email@example.com - 06-23-2018
I was able to make my forum account work just by simply creating another one hehe. Hopefully that doesn't mess up my account there on the ab4d official website.
So I am using a DesktopDuplicator as seen here https://github.com/Deathspike/Hansha . Once I get access the Desktop Duplicator in a running program, it outputs:
now with the following line of code next, I am able to copy the contents of the Newpixels to a Bitmap:
Following that, I need to convert the Bitmap to a BitmapSource and then from BitmapSource to ImageBrush
and then imageBrush to DiffuseMaterial to apply it to the material of an object.
But the function CreateBitmapSource here is overloading the performance like crazy. It really lags and bottlenecks the whole performance:
Does anybody have any clues on an alternative?
I will scour the AB4D samples to find clues about applying textures to an object's material.
EDIT 2018-06-23 - 22h00 - I have found an alternative. But it doesn't fix the lag issue and so I will divide the desktop screen and try to make threads work on them to lower the load. Here is the alternative that I found:
from here: https://stackoverflow.com/questions/6484357/converting-bitmapimage-to-bitmap-and-vice-versa
RE: convert SharpDXDirect3D11 Texture2D? - abenedik - 06-25-2018
I am sorry for the problems with the forum. I will check the spam filter settings again and see if there is anything I can do to improve that.
Now to your question.
From what you have written I think that you should be able to use the texture2D directly as it is on the GPU without copying it to main memory, converting it to GDI+ bitmap, then to WPF bitmap. And from there in DXEngine back to DirectX shader resource view and sending it back to GPU. There is a lot of overhead especially with sending the image from the gpu and back.
To try this use the following code to first create a ShaderResourceView from the texture2D object:
Then you can create a DXEngine material that will use that texture:
You can then use the standardMaterial to create a MeshObjectNode or if you are using WPF 3D objects, you can assign it to WPF Material with:
This will use the standardMaterial whenever the DXEngine will render an object with the diffuseMaterial.
I hope that this code will work for you.
RE: convert SharpDXDirect3D11 Texture2D? - firstname.lastname@example.org - 06-26-2018
Hi Mr. Benedik, Thank you for you fast response.
There is a line of code that gives me an error in the Console. It says that there is an invalid parameter. The device is created at the start of the scene and the scene can display a cube perfectly but it outputs an invalid parameter when I try to create the ShaderResourceView.
I scoured the internet a bit for info on that but the info is really hard to find on SharpDX. I am using the 188.8.131.52 SharpDX dll's. I Wonder if that is the problem. I tried creating a Texture2D to see the results like this:
But to no avail. It says that there is still an invalid parameter... Anyway, if you have any insight on what might be going on?
EDIT 2018-06-26 - 02h43am - I have found the culprit. I am sending the MainDXViewportView.DXScene.DXDevice.Device to the DesktopDuplication to Acquire the Frame... It seems that using this Device again to create the ShaderResourceView isn't working. I will review this part and try to understand why I can't use the same MainDXViewportView.DXScene.DXDevice.Device. It's probably Something that is easy to understand for others but me, I have no clue. I am in uncharted waters right now. Sorry for not debugging properly and asking questions.
RE: convert SharpDXDirect3D11 Texture2D? - abenedik - 06-29-2018
After some thinking, I see that the problem with my recommendation is that the ScreenFrame.texture2D that you got is probably not created in such a way that it can be used use as ShaderResourceView.
To use Texture2D for that, it needs to be create with Texture2DDescription that have:
Usage = ResourceUsage.Default
BindFlags = BindFlags.ShaderResource
If you can control how this Texture2D is created, then try those settings.