WinRT: added support for alpha-blended texture rendering
authorDavid Ludwig <dludwig@pobox.com>
Sat, 23 Feb 2013 22:58:09 -0500
changeset 84427046465c646c
parent 8441 89aee82477bb
child 8443 210a3869a783
WinRT: added support for alpha-blended texture rendering
src/render/direct3d11/SDL_render_d3d11.cpp
     1.1 --- a/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Feb 23 20:22:19 2013 -0500
     1.2 +++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Feb 23 22:58:09 2013 -0500
     1.3 @@ -89,18 +89,22 @@
     1.4  HRESULT D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer);
     1.5  HRESULT D3D11_HandleDeviceLost(SDL_Renderer * renderer);
     1.6  
     1.7 -extern "C" {
     1.8 -    SDL_RenderDriver D3D11_RenderDriver = {
     1.9 +// WinRT, TODO: fill in the Direct3D 11.1 renderer's max texture width and height
    1.10 +extern "C" SDL_RenderDriver D3D11_RenderDriver = {
    1.11      D3D11_CreateRenderer,
    1.12      {
    1.13 -     "direct3d 11.1",
    1.14 -     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
    1.15 -     1,
    1.16 -     {SDL_PIXELFORMAT_RGB888},
    1.17 -     0,
    1.18 -     0}
    1.19 -    };
    1.20 -}
    1.21 +        "direct3d 11.1",
    1.22 +        (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),    // flags.  see SDL_RendererFlags
    1.23 +        2,                          // num_texture_formats
    1.24 +        {                           // texture_formats
    1.25 +            SDL_PIXELFORMAT_RGB888,
    1.26 +            SDL_PIXELFORMAT_ARGB8888
    1.27 +        },
    1.28 +        0,                          // max_texture_width
    1.29 +        0                           // max_texture_height
    1.30 +    }
    1.31 +};
    1.32 +
    1.33  
    1.34  //typedef struct
    1.35  //{
    1.36 @@ -782,6 +786,20 @@
    1.37      D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
    1.38      D3D11_TextureData *textureData;
    1.39      HRESULT result;
    1.40 +    DXGI_FORMAT textureFormat = DXGI_FORMAT_UNKNOWN;
    1.41 +
    1.42 +    switch (texture->format) {
    1.43 +        case SDL_PIXELFORMAT_ARGB8888:
    1.44 +            textureFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
    1.45 +            break;
    1.46 +        case SDL_PIXELFORMAT_RGB888:
    1.47 +            textureFormat = DXGI_FORMAT_B8G8R8X8_UNORM;
    1.48 +            break;
    1.49 +        default:
    1.50 +            SDL_SetError("%s, An unsupported SDL pixel format (0x%x) was specified",
    1.51 +                __FUNCTION__, texture->format);
    1.52 +            return -1;
    1.53 +    }
    1.54  
    1.55      textureData = new D3D11_TextureData;
    1.56      if (!textureData) {
    1.57 @@ -799,7 +817,7 @@
    1.58      textureDesc.Height = texture->h;
    1.59      textureDesc.MipLevels = 1;
    1.60      textureDesc.ArraySize = 1;
    1.61 -    textureDesc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
    1.62 +    textureDesc.Format = textureFormat;
    1.63      textureDesc.SampleDesc.Count = 1;
    1.64      textureDesc.SampleDesc.Quality = 0;
    1.65      textureDesc.Usage = D3D11_USAGE_DYNAMIC;
    1.66 @@ -1099,8 +1117,13 @@
    1.67  		0,
    1.68  		0
    1.69  		);
    1.70 +}
    1.71  
    1.72 -    switch (renderer->blendMode) {
    1.73 +static void
    1.74 +D3D11_RenderSetBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
    1.75 +{
    1.76 +    D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
    1.77 +    switch (blendMode) {
    1.78          case SDL_BLENDMODE_BLEND:
    1.79              rendererData->d3dContext->OMSetBlendState(rendererData->blendModeBlend.Get(), 0, 0xFFFFFFFF);
    1.80              break;
    1.81 @@ -1168,6 +1191,7 @@
    1.82  
    1.83      for (int i = 0; i < count; ++i) {
    1.84          D3D11_RenderStartDrawOp(renderer);
    1.85 +        D3D11_RenderSetBlendMode(renderer, renderer->blendMode);
    1.86  
    1.87  #if 0
    1.88          // Set colors for the test pattern:
    1.89 @@ -1211,6 +1235,7 @@
    1.90      D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
    1.91  
    1.92      D3D11_RenderStartDrawOp(renderer);
    1.93 +    D3D11_RenderSetBlendMode(renderer, texture->blendMode);
    1.94  
    1.95      // WinRT, TODO: get srcrect working in tandem with SDL_RenderCopy, etc.
    1.96      VertexPositionColor vertices[] = {