Monday, March 9, 2009

CreateImageSurface failure in Direct3D Mobile

For augmented reality applications, it is required to render real-time video sequences on the background. Usually, we use texture mapping for this on both OpenGL(ES) or Direct3D (mobile).

In Direct3D Mobile (D3DM), there are two choises usually used by users.

1. Lock the texture, copy pixel data from input video, and unlock the texture.
2. Create an image surface where the video is copied. Lock the surface, copy pixel data from input video, unlock the surface, and update the texture with CopyRect method.

When I implement both methods(to choose a faster one), both methods runs well on the emulaltor. However, I encountered several problems on my smart phone (Samsung M480, Windows Mobile 6.0).

At first, lockable texture is not supported by M480. When I checked the capability using this code,


the result was false and calling D3DMXCreateTexture function with D3DMUSAGE_LOCKABLE option failed, of course.

Then, I tried the 2nd method, using image surface but the code did not work again. This time, the error occurred when creating surface. I tried to find documents about this problem on the web, but get nothing. After I tried many different parameters, I finally figured out it.

The CreateImageSurface function always fails when I created the image surface with the format D3DMFMT_R8G8B8 on my device, M480. After I changed the image format to D3DMFMT_R5G6B5, which may be natively supported the hardware on M480, the code works well.

We need to check the capability of the hardware we are working on when we want to work with lockable things (such as textures, vertex buffers, or iamge surfaces). Even though the code runs well on the emulator, it does not gaurantee the code works well on the device. Another thing we have to consider is that try another format when your device cannot create an image surface.

I'm not sure how the textures and image surfaces work on the other devices. Does Direct3D Mobile provide the same functionalities on all the devices using WM6, or does the functionalities depend on hardware driver implementations of vendors ??

1 comment:

  1. Thanks for this valuable information, I was wondering why it didn't work... checking device caps always helps !

    And so Omnia (Samsung also) only supports the following
    **ListAdapterMode: ModeCount=1
    0:DispalyMode 480 x 800 refreshRate=60 format=4 D3DMFMT_R5G6B5
    * D3DMFMT_D32
    * D3DMFMT_D16

    Pretty bad... :(