src/render/SDL_render.c
changeset 12909 8e27bc5f03d8
parent 12808 8a4b1beb4f6e
child 12910 dd9169424181
equal deleted inserted replaced
12908:ec53745bdb23 12909:8e27bc5f03d8
   837     SDL_bool batching = SDL_TRUE;
   837     SDL_bool batching = SDL_TRUE;
   838     const char *hint;
   838     const char *hint;
   839 
   839 
   840     if (!window) {
   840     if (!window) {
   841         SDL_SetError("Invalid window");
   841         SDL_SetError("Invalid window");
   842         return NULL;
   842         goto error;
   843     }
   843     }
   844 
   844 
   845     if (SDL_GetRenderer(window)) {
   845     if (SDL_GetRenderer(window)) {
   846         SDL_SetError("Renderer already associated with window");
   846         SDL_SetError("Renderer already associated with window");
   847         return NULL;
   847         goto error;
   848     }
   848     }
   849 
   849 
   850     if (SDL_GetHint(SDL_HINT_RENDER_VSYNC)) {
   850     if (SDL_GetHint(SDL_HINT_RENDER_VSYNC)) {
   851         if (SDL_GetHintBoolean(SDL_HINT_RENDER_VSYNC, SDL_TRUE)) {
   851         if (SDL_GetHintBoolean(SDL_HINT_RENDER_VSYNC, SDL_TRUE)) {
   852             flags |= SDL_RENDERER_PRESENTVSYNC;
   852             flags |= SDL_RENDERER_PRESENTVSYNC;
   886                 }
   886                 }
   887             }
   887             }
   888         }
   888         }
   889         if (index == n) {
   889         if (index == n) {
   890             SDL_SetError("Couldn't find matching render driver");
   890             SDL_SetError("Couldn't find matching render driver");
   891             return NULL;
   891             goto error;
   892         }
   892         }
   893     } else {
   893     } else {
   894         if (index >= SDL_GetNumRenderDrivers()) {
   894         if (index >= SDL_GetNumRenderDrivers()) {
   895             SDL_SetError("index must be -1 or in the range of 0 - %d",
   895             SDL_SetError("index must be -1 or in the range of 0 - %d",
   896                          SDL_GetNumRenderDrivers() - 1);
   896                          SDL_GetNumRenderDrivers() - 1);
   897             return NULL;
   897             goto error;
   898         }
   898         }
   899         /* Create a new renderer instance */
   899         /* Create a new renderer instance */
   900         renderer = render_drivers[index]->CreateRenderer(window, flags);
   900         renderer = render_drivers[index]->CreateRenderer(window, flags);
   901         batching = SDL_FALSE;
   901         batching = SDL_FALSE;
   902     }
   902     }
   903 
   903 
   904     if (renderer) {
   904     if (!renderer) {
   905         VerifyDrawQueueFunctions(renderer);
   905         goto error;
   906 
   906     }
   907         /* let app/user override batching decisions. */
   907 
   908         if (renderer->always_batch) {
   908     VerifyDrawQueueFunctions(renderer);
   909             batching = SDL_TRUE;
   909 
   910         } else if (SDL_GetHint(SDL_HINT_RENDER_BATCHING)) {
   910     /* let app/user override batching decisions. */
   911             batching = SDL_GetHintBoolean(SDL_HINT_RENDER_BATCHING, SDL_TRUE);
   911     if (renderer->always_batch) {
   912         }
   912         batching = SDL_TRUE;
   913 
   913     } else if (SDL_GetHint(SDL_HINT_RENDER_BATCHING)) {
   914         renderer->batching = batching;
   914         batching = SDL_GetHintBoolean(SDL_HINT_RENDER_BATCHING, SDL_TRUE);
   915         renderer->magic = &renderer_magic;
   915     }
   916         renderer->window = window;
   916 
   917         renderer->target_mutex = SDL_CreateMutex();
   917     renderer->batching = batching;
   918         renderer->scale.x = 1.0f;
   918     renderer->magic = &renderer_magic;
   919         renderer->scale.y = 1.0f;
   919     renderer->window = window;
   920         renderer->dpi_scale.x = 1.0f;
   920     renderer->target_mutex = SDL_CreateMutex();
   921         renderer->dpi_scale.y = 1.0f;
   921     renderer->scale.x = 1.0f;
   922 
   922     renderer->scale.y = 1.0f;
   923         /* new textures start at zero, so we start at 1 so first render doesn't flush by accident. */
   923     renderer->dpi_scale.x = 1.0f;
   924         renderer->render_command_generation = 1;
   924     renderer->dpi_scale.y = 1.0f;
   925 
   925 
   926         if (window && renderer->GetOutputSize) {
   926     /* new textures start at zero, so we start at 1 so first render doesn't flush by accident. */
   927             int window_w, window_h;
   927     renderer->render_command_generation = 1;
   928             int output_w, output_h;
   928 
   929             if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
   929     if (window && renderer->GetOutputSize) {
   930                 SDL_GetWindowSize(renderer->window, &window_w, &window_h);
   930         int window_w, window_h;
   931                 renderer->dpi_scale.x = (float)window_w / output_w;
   931         int output_w, output_h;
   932                 renderer->dpi_scale.y = (float)window_h / output_h;
   932         if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
   933             }
   933             SDL_GetWindowSize(renderer->window, &window_w, &window_h);
   934         }
   934             renderer->dpi_scale.x = (float)window_w / output_w;
   935 
   935             renderer->dpi_scale.y = (float)window_h / output_h;
   936         if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) {
   936         }
   937             renderer->hidden = SDL_TRUE;
   937     }
   938         } else {
   938 
   939             renderer->hidden = SDL_FALSE;
   939     if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) {
   940         }
   940         renderer->hidden = SDL_TRUE;
   941 
   941     } else {
   942         SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
   942         renderer->hidden = SDL_FALSE;
   943 
   943     }
   944         SDL_RenderSetViewport(renderer, NULL);
   944 
   945 
   945     SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
   946         SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
   946 
   947 
   947     SDL_RenderSetViewport(renderer, NULL);
   948         SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
   948 
   949                     "Created renderer: %s", renderer->info.name);
   949     SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
   950     }
   950 
       
   951     SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
       
   952                 "Created renderer: %s", renderer->info.name);
       
   953 
   951     return renderer;
   954     return renderer;
       
   955 
       
   956 error:
       
   957     return NULL;
       
   958 
   952 #else
   959 #else
   953     SDL_SetError("SDL not built with rendering support");
   960     SDL_SetError("SDL not built with rendering support");
   954     return NULL;
   961     return NULL;
   955 #endif
   962 #endif
   956 }
   963 }