The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Windows Phone 8 - is it possible to access DX directly?
Limanima


Joined: 09 Oct 2013
Posts: 75
I'm back from vacation!
And now I have a few more questions to post regarding Windows Phone 8.
I'm starting to port my engine to WP, but I'm facing some challenges.
I have specific renderers for Windows (opengl), android/ios (opengles) and now I want a specific DX renderer for Win 8.
I've looked into the SDL API but I can't find a way to access the DX context.
At this moment I'm accessing DX data objects thru SDL_Renderer->driverdata and casting it to D3D11_RenderData structure (which I to copied from SDL_render_d3d11.c).
This isn't obviously a good solution.
Is there a way I can access DX similar to opengl?

Another question: SDL uses a swap chain for rendering, what's the API call to swap the render targets? I'm looking for the SDL_GL_SwapWindow equivalent.


Not sure if all this makes any sense...

Thanks
Windows Phone 8 - is it possible to access DX directly?
meklu
Guest

The SDL render equivalent of SDL_GL_SwapBuffers is SDL_RenderPresent, the rest I'm afraid I can't help you with.

--
Melker Narikka

Limanima kirjoitti Mon Aug 25 2014 17:37:30 GMT+0300 (EEST):
Quote:
I'm back from vacation!
And now I have a few more questions to post regarding Windows Phone 8.
I'm starting to port my engine to WP, but I'm facing some challenges.
I have specific renderers for Windows (opengl), android/ios (opengles) and now I want a specific DX renderer for Win 8.
I've looked into the SDL API but I can't find a way to access the DX context.
At this moment I'm accessing DX data objects thru SDL_Renderer->driverdata and casting it to D3D11_RenderData structure (which I to copied from SDL_render_d3d11.c).
This isn't obviously a good solution.
Is there a way I can access DX similar to opengl?

Another question: SDL uses a swap chain for rendering, what's the API call to swap the render targets? I'm looking for the SDL_GL_SwapWindow equivalent.


Not sure if all this makes any sense...

Thanks


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Re: Windows Phone 8 - is it possible to access DX directly?
Limanima


Joined: 09 Oct 2013
Posts: 75
meklu wrote:
The SDL render equivalent of SDL_GL_SwapBuffers is SDL_RenderPresent, the rest I'm afraid I can't help you with.


I've already tried that, but I'm getting this:

"identifier "SDL_RenderPresent_REAL" is undefined"

I'm going to try to understand why is this undefined.
Re: Windows Phone 8 - is it possible to access DX directly?
Limanima


Joined: 09 Oct 2013
Posts: 75
OK, I'm getting that error because I'm including SDL_sysrender.h.
I'm including this so I can have access to the SDL_Renderer structure and get the driverdata member.

I know that what I'm doing is plane wrong, that's why I want to access DX context the correct way (if possible of course).
Re: Windows Phone 8 - is it possible to access DX directly?
DLudwig


Joined: 09 Feb 2012
Posts: 179
Limanima wrote:
Is there a way I can access DX similar to OpenGL?


There currently isn't any explicit support for accessing the internals of the SDL/WinRT's Direct3D 11.x renderer (outside of SDL). It might be possible, however I haven't tried it myself. It is, however, possible to create your own, complete-set of Direct3D 11 resources (swap chain, textures, etc.), which'll get attached to the SDL-managed OS' native window (WinRT calls this a 'CoreWindow'; attached to D3D11 via IDXGIFactory::CreateSwapChainForCoreWindow, detailed at http://msdn.microsoft.com/en-us/library/windows/apps/hh404559(v=vs.85).aspx ). From there, SDL can be used for input, audio, etc., while Direct3D 11.x gets used for rendering, swap chain management and presentation, etc.

To get the WinRT native window, SDL_GetWindowWMInfo can be used. A pointer to the CoreWindow will be in the SDL_SysWMinfo struct, via the field, 'info.winrt.window' (minus the quote marks).

To note, SDL/WinRT does have some experimental support for rendering content via OpenGL ES 2.x, via a Microsoft Open Technologies driven port of Google's ANGLE library (which emulates OpenGL ES 2.x on top of Direct3D), to the WinRT family of platforms. The port is available at https://github.com/msopentech/angle, if you'd like to take a look. Getting it running is a matter of compiling it's various components, packaging the .dll files in your app, then using SDL to create an OpenGL content. SDL will attempt to load the appropriate DLL files, and create an OpenGL context via ANGLE (which'll issue appropriate Direct3D calls). A few notes on this though:

1. I've never tried using OpenGL ES via ANGLE on Windows Phone 8, only Windows 8 (in it's 'Metro' environment). I suspect that it would work off the bat, but haven't explicitly-tested this.

2. If you're compiling a Windows Phone 8.0 app (as opposed to a Windows Phone 8.1 app), and end up using ANGLE, you'll need to precompile your shaders, as WP 8.0 doesn't allow store-distributed apps to compile shaders at runtime. A shader compiler can be packaged into developer-only/non-store builds, however store-distributed apps must precompile the shaders. More details on this are on MS Open-Tech's ANGLE page (https://github.com/msopentech/angle).


Quote:
Another question: SDL uses a swap chain for rendering, what's the API call to swap the render targets? I'm looking for the SDL_GL_SwapWindow equivalent.


If you're using a custom, Direct3D 11 renderer, you wouldn't use SDL to present a frame, but rather the equivalent Direct3D 11 calls (IDXGISwapChain::Present, for example).

If you're only using SDL_Renderer to draw content (and avoiding a custom, Direct3D 11 renderer), you can use SDL_RenderPresent to show content.


-- David L.
Re: Windows Phone 8 - is it possible to access DX directly?
Limanima


Joined: 09 Oct 2013
Posts: 75
DLudwig wrote:
Limanima wrote:
Is there a way I can access DX similar to OpenGL?


There currently isn't any explicit support for accessing the internals of the SDL/WinRT's Direct3D 11.x renderer (outside of SDL). It might be possible, however I haven't tried it myself. It is, however, possible to create your own, complete-set of Direct3D 11 resources (swap chain, textures, etc.), which'll get attached to the SDL-managed OS' native window (WinRT calls this a 'CoreWindow'; attached to D3D11 via IDXGIFactory::CreateSwapChainForCoreWindow, detailed at http://msdn.microsoft.com/en-us/library/windows/apps/hh404559(v=vs.85).aspx ). From there, SDL can be used for input, audio, etc., while Direct3D 11.x gets used for rendering, swap chain management and presentation, etc.

To get the WinRT native window, SDL_GetWindowWMInfo can be used. A pointer to the CoreWindow will be in the SDL_SysWMinfo struct, via the field, 'info.winrt.window' (minus the quote marks).

To note, SDL/WinRT does have some experimental support for rendering content via OpenGL ES 2.x, via a Microsoft Open Technologies driven port of Google's ANGLE library (which emulates OpenGL ES 2.x on top of Direct3D), to the WinRT family of platforms. The port is available at https://github.com/msopentech/angle, if you'd like to take a look. Getting it running is a matter of compiling it's various components, packaging the .dll files in your app, then using SDL to create an OpenGL content. SDL will attempt to load the appropriate DLL files, and create an OpenGL context via ANGLE (which'll issue appropriate Direct3D calls). A few notes on this though:

1. I've never tried using OpenGL ES via ANGLE on Windows Phone 8, only Windows 8 (in it's 'Metro' environment). I suspect that it would work off the bat, but haven't explicitly-tested this.

2. If you're compiling a Windows Phone 8.0 app (as opposed to a Windows Phone 8.1 app), and end up using ANGLE, you'll need to precompile your shaders, as WP 8.0 doesn't allow store-distributed apps to compile shaders at runtime. A shader compiler can be packaged into developer-only/non-store builds, however store-distributed apps must precompile the shaders. More details on this are on MS Open-Tech's ANGLE page (https://github.com/msopentech/angle).


Quote:
Another question: SDL uses a swap chain for rendering, what's the API call to swap the render targets? I'm looking for the SDL_GL_SwapWindow equivalent.


If you're using a custom, Direct3D 11 renderer, you wouldn't use SDL to present a frame, but rather the equivalent Direct3D 11 calls (IDXGISwapChain::Present, for example).

If you're only using SDL_Renderer to draw content (and avoiding a custom, Direct3D 11 renderer), you can use SDL_RenderPresent to show content.


-- David L.


Thanks for the insight.
I'm trying my initial route: hack SDL to get access to the SDL_Renderer.driverData member, and then create my own shaders, viewport, rasterizer etc.
It's seems to be working, but I still haven't managed to get something to be drawn on screen. At least I'm not getting DX errors, and I already have everything in place, vertex/index buffers, shaders etc. I'm trying to understand what's going on.
Last DX version I've used was DX 5.0 and it was a long time ago...
At least ClearRenderTargetView is working, because I can change the background color Very Happy.
Re: Windows Phone 8 - is it possible to access DX directly?
DLudwig


Joined: 09 Feb 2012
Posts: 179
Limanima wrote:
I'm trying my initial route: hack SDL to get access to the SDL_Renderer.driverData member, and then create my own shaders, viewport, rasterizer etc.
It's seems to be working, but I still haven't managed to get something to be drawn on screen. At least I'm not getting DX errors, and I already have everything in place, vertex/index buffers, shaders etc. I'm trying to understand what's going on.
Last DX version I've used was DX 5.0 and it was a long time ago...
At least ClearRenderTargetView is working, because I can change the background color Very Happy.


Here's one tip: try turning on Direct3D 11's debug mode. If you're using the SDL_Renderer API to create this, use SDL_SetHint to set SDL_HINT_RENDER_DIRECT3D11_DEBUG to "1", doing so -before- creating the renderer. If, at some point, you end up creating your own D3D device (and swap chain, etc.), you can turn on debug mode by passing in the D3D11_CREATE_DEVICE_DEBUG flag to D3D11CreateDevice.

Best of luck!
-- David L.
Re: Windows Phone 8 - is it possible to access DX directly?
Limanima


Joined: 09 Oct 2013
Posts: 75
DLudwig wrote:


Here's one tip: try turning on Direct3D 11's debug mode. If you're using the SDL_Renderer API to create this, use SDL_SetHint to set SDL_HINT_RENDER_DIRECT3D11_DEBUG to "1", doing so -before- creating the renderer. If, at some point, you end up creating your own D3D device (and swap chain, etc.), you can turn on debug mode by passing in the D3D11_CREATE_DEVICE_DEBUG flag to D3D11CreateDevice.

Best of luck!
-- David L.


Already did that. Wink

I'm still chasing the problem. It can be anything. Wrong viewport, projection matrix, shaders, buffers, etc..
I'm getting ready for a few hours chasing this.
Re: Windows Phone 8 - is it possible to access DX directly?
Limanima


Joined: 09 Oct 2013
Posts: 75
I think I got it, took me some time, but I think I know why nothing is being rendered.
The projection matrix is wrong. Opengl uses a right handed system, and DirectX uses a left handed system!

Next step: remove all the test code I have and add texture support to the shader.
Re: Windows Phone 8 - is it possible to access DX directly?
Limanima


Joined: 09 Oct 2013
Posts: 75
Limanima wrote:
I think I got it, took me some time, but I think I know why nothing is being rendered.
The projection matrix is wrong. Opengl uses a right handed system, and DirectX uses a left handed system!

Next step: remove all the test code I have and add texture support to the shader.


There's another difference in matrix math. Transformation matrices have to be transposed.
Limanima


Joined: 09 Oct 2013
Posts: 75
YEAH!
After a few hours (days actually, and a lot of headaches) I finally have the game working on WP!
All sprites are filled rects for now, but it's working. All I need now is a texture shader (and to adjust a few more things).