src/render/direct3d/SDL_render_d3d.c
changeset 5484 e20c93bc9122
parent 5299 33987021a1ed
child 5535 96594ac5fd1a
equal deleted inserted replaced
5483:ccec742c9b7d 5484:e20c93bc9122
    24 #if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
    24 #if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
    25 
    25 
    26 
    26 
    27 #include "../../core/windows/SDL_windows.h"
    27 #include "../../core/windows/SDL_windows.h"
    28 
    28 
       
    29 #include "SDL_hints.h"
    29 #include "SDL_loadso.h"
    30 #include "SDL_loadso.h"
    30 #include "SDL_syswm.h"
    31 #include "SDL_syswm.h"
    31 #include "../SDL_sysrender.h"
    32 #include "../SDL_sysrender.h"
    32 
    33 
    33 #if SDL_VIDEO_RENDER_D3D
    34 #if SDL_VIDEO_RENDER_D3D
   135     IDirect3DDevice9 *device;
   136     IDirect3DDevice9 *device;
   136     UINT adapter;
   137     UINT adapter;
   137     D3DPRESENT_PARAMETERS pparams;
   138     D3DPRESENT_PARAMETERS pparams;
   138     SDL_bool updateSize;
   139     SDL_bool updateSize;
   139     SDL_bool beginScene;
   140     SDL_bool beginScene;
       
   141     D3DTEXTUREFILTERTYPE scaleMode;
   140 } D3D_RenderData;
   142 } D3D_RenderData;
   141 
   143 
   142 typedef struct
   144 typedef struct
   143 {
   145 {
   144     IDirect3DTexture9 *texture;
   146     IDirect3DTexture9 *texture;
       
   147     D3DTEXTUREFILTERTYPE scaleMode;
   145 } D3D_TextureData;
   148 } D3D_TextureData;
   146 
   149 
   147 typedef struct
   150 typedef struct
   148 {
   151 {
   149     float x, y, z;
   152     float x, y, z;
   449         D3D_DestroyRenderer(renderer);
   452         D3D_DestroyRenderer(renderer);
   450         D3D_SetError("CreateDevice()", result);
   453         D3D_SetError("CreateDevice()", result);
   451         return NULL;
   454         return NULL;
   452     }
   455     }
   453     data->beginScene = SDL_TRUE;
   456     data->beginScene = SDL_TRUE;
       
   457     data->scaleMode = D3DTEXF_FORCE_DWORD;
   454 
   458 
   455     /* Get presentation parameters to fill info */
   459     /* Get presentation parameters to fill info */
   456     result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
   460     result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
   457     if (FAILED(result)) {
   461     if (FAILED(result)) {
   458         D3D_DestroyRenderer(renderer);
   462         D3D_DestroyRenderer(renderer);
   535     if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
   539     if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
   536         data->updateSize = SDL_TRUE;
   540         data->updateSize = SDL_TRUE;
   537     }
   541     }
   538 }
   542 }
   539 
   543 
       
   544 static D3DTEXTUREFILTERTYPE
       
   545 GetScaleQuality(void)
       
   546 {
       
   547     const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
       
   548 
       
   549     if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
       
   550         return D3DTEXF_POINT;
       
   551     } else if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) {
       
   552         return D3DTEXF_LINEAR;
       
   553     } else {
       
   554         return D3DTEXF_ANISOTROPIC;
       
   555     }
       
   556 }
       
   557 
   540 static int
   558 static int
   541 D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   559 D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   542 {
   560 {
   543     D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
   561     D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
   544     SDL_Window *window = renderer->window;
   562     SDL_Window *window = renderer->window;
   551     data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data));
   569     data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data));
   552     if (!data) {
   570     if (!data) {
   553         SDL_OutOfMemory();
   571         SDL_OutOfMemory();
   554         return -1;
   572         return -1;
   555     }
   573     }
       
   574     data->scaleMode = GetScaleQuality();
   556 
   575 
   557     texture->driverdata = data;
   576     texture->driverdata = data;
   558 
   577 
   559 #ifdef USE_DYNAMIC_TEXTURE
   578 #ifdef USE_DYNAMIC_TEXTURE
   560     if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
   579     if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
  1016     vertices[3].u = minu;
  1035     vertices[3].u = minu;
  1017     vertices[3].v = maxv;
  1036     vertices[3].v = maxv;
  1018 
  1037 
  1019     D3D_SetBlendMode(data, texture->blendMode);
  1038     D3D_SetBlendMode(data, texture->blendMode);
  1020 
  1039 
  1021     IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
  1040     if (texturedata->scaleMode != data->scaleMode) {
  1022                                      D3DTEXF_LINEAR);
  1041         IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
  1023     IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
  1042                                          texturedata->scaleMode);
  1024                                      D3DTEXF_LINEAR);
  1043         IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
       
  1044                                          texturedata->scaleMode);
       
  1045         data->scaleMode = texturedata->scaleMode;
       
  1046     }
  1025 
  1047 
  1026     result =
  1048     result =
  1027         IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)
  1049         IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)
  1028                                     texturedata->texture);
  1050                                     texturedata->texture);
  1029     if (FAILED(result)) {
  1051     if (FAILED(result)) {