Rick answers conversations about methods that you can use if you don't need to lose hardware acceleration. I am focusing on how to do this using a significant amount of GPU acceleration.
To speed up the rendering of equipment and get maximum performance, you will want to switch from ID2DHwndRenderTarget to use the newer ID2DDevice and ID2DDeviceContext interfaces. This, frankly, does not add that there is much more logic to your code, and the performance benefits are substantial. It also works on Windows 7 with a platform update. To summarize the process:
- Create a DXGI factory when creating a D2D factory.
- Create a D3D11 device and a D2D device to match.
- Create a swap chain using the DXGI factory and the D3D device.
- Define a swap chain for your back buffer and wrap it in a D2D bitmap.
- Render, as before, between calls to BeginDraw () and EndDraw (). Remember to untie the back buffer and destroy its bitmap.
- Call Present () in the swap chain to see the results.
- Repeat with 4.
Once you do, you have unlocked a number of possible solutions. Probably the easiest and most effective way to solve your exact problem (color channel sharing) is to use the color matrix as one of the other answers mentioned. It is important to recognize that for this you need to use the new ID2DDeviceContext interface, not ID2DHwndRenderTarget. There are many other effects that can perform more complex operations if you want to. Here are some of the most useful for simple pixel manipulation:
To solve the problem of manipulating pixels directly, without discarding hardware acceleration or performing tons of copying, there are two options. First, write a pixel shader and wrap it with a fully customizable D2D effect. This is more than just getting the pixel buffer on the processor and doing the old-fashioned bit-mashing, but all this happens much faster on the GPU. The D2D effects frame also makes it very easy to reuse your effect for other purposes, combine it with other effects, etc.
In those moments when you absolutely need to manipulate the pixels of the processor, but still want to achieve significant acceleration, you can control your displayed D3D11 textures. For example, you can use intermediate textures if you want to manipulate your texture resources asynchronously from the CPU. There is another answer that goes in more detail. See ID3D11Texture2D for more details.
source share