I'm trying to copy an image onto a Unity texture from C++. The image is 320x240px, and is in RGBA format. I've verified that the image is okay.
To copy I use UpdateSubresource, here's the code:
GraphicDeviceD3D11* gdevice = (GraphicDeviceD3D11*)graphic_device;
ID3D11DeviceContext* ctx = NULL;
gdevice->d3d11device->lpVtbl->GetImmediateContext(gdevice->d3d11device, &ctx);
if (texturePointer) {
ctx->lpVtbl->UpdateSubresource(ctx, (ID3D11Resource *)texturePointer, 0, NULL, image, imageWidth * 4, 0);
}
ctx->lpVtbl->Release(ctx);
I'm hardly a d3d11 expert, and am not sure I'm using this function correctly. The parameters of the image given to UpdateSubresource are only the image buffer pointer and the stride, but not the height of the image OR the length of the buffer.
How does UpdateResource know when to stop copying?
This code worked for me for some images, but doesn't work for others - It raises an Access Violation on memory just a bit beyond the image buffer size - So that hints me I'm not setting the limits somewhere.
Can someone shed some light on that?
You're using the function correctly - the destination resource (referred to by texturePointer
in your case) contains all the required data and the method will work as expected.
However, what is this lpVtbl
indirection for? If you're using c++ (and not c), you probably should stick with simple pInstance->Method()
approach for invoking COM methods.