Since @paroj suggested trying with DX9, I've been working on that, and now I'm stuck with something that could be useful in both DX9 and DX11.
The error I'm encountering now is related to the surface pointer I'm trying to use. Basically, after initializing Ogre with a basic scene featuring Sinbad, I call a function to create my render texture.
Code: Select all
public void InitRenderTarget()
{
texturePtr = TextureManager.getSingleton().createManual(
"SharedTexture",
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
TextureType.TEX_TYPE_2D,
800,
600,
32,
0,
PixelFormat.PF_R8G8B8A8,
(int)0x20);
renderTarget = texturePtr.getBuffer().getRenderTarget();
}
After this, I use the renderTarget to get the custom attribute "DDBACKBUFFER" and set my D3DImage back buffer with the pointer from renderTarget.getCustomAttribute(). Here's the issue: in the old version using Mogre, renderTarget.getCustomAttribute() used to accept two parameters. One was a string indicating the attribute you wanted to use, and the other was an output parameter for a pointer, like this code in Mogre:
Code: Select all
IntPtr surface;
_renTarget.GetCustomAttribute("DDBACKBUFFER", out surface);
SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface, true);
The problem now is that renderTarget.getCustomAttribute() doesn't accept output parameters anymore. Essentially, you're given a pointer that can only be passed without using out or ref. The method is now like this:
Code: Select all
public unsafe void AttachRenderTarget()
{
try
{
IntPtr surface = IntPtr.Zero
renderTarget.getCustomAttribute("DDBACKBUFFER", surface);
Lock();
SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface, false);
}
finally
{
Unlock();
}
}
When running the code, an error occurs: "System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'". What I'm trying to do now is use renderTarget.getCustomAttribute("DDBACKBUFFER"), which returns a uint, but after converting the uint to an IntPtr, the same error occurs, but this time on the SetBackBuffer line.
Code: Select all
public unsafe void AttachRenderTarget()
{
try
{
uint p;
IntPtr surface = IntPtr.Zero;
p = renderTarget.getCustomAttribute("DDBACKBUFFER");
surface = new IntPtr(p);
Lock();
SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface, false);
}
finally
{
Unlock();
}
}
Here is how the code looks now.