MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / SDL_CreateWindowTexture

Function SDL_CreateWindowTexture

deps/SDL2/src/video/SDL_video.c:258–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258static int
259SDL_CreateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
260{
261 SDL_WindowTextureData *data;
262
263 data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
264 if (!data) {
265 SDL_Renderer *renderer = NULL;
266 int i;
267 const char *hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
268
269 /* Check to see if there's a specific driver requested */
270 if (hint && *hint != '0' && *hint != '1' &&
271 SDL_strcasecmp(hint, "true") != 0 &&
272 SDL_strcasecmp(hint, "false") != 0 &&
273 SDL_strcasecmp(hint, "software") != 0) {
274 for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
275 SDL_RendererInfo info;
276 SDL_GetRenderDriverInfo(i, &info);
277 if (SDL_strcasecmp(info.name, hint) == 0) {
278 renderer = SDL_CreateRenderer(window, i, 0);
279 break;
280 }
281 }
282 }
283
284 if (!renderer) {
285 for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
286 SDL_RendererInfo info;
287 SDL_GetRenderDriverInfo(i, &info);
288 if (SDL_strcmp(info.name, "software") != 0) {
289 renderer = SDL_CreateRenderer(window, i, 0);
290 if (renderer) {
291 break;
292 }
293 }
294 }
295 }
296 if (!renderer) {
297 return SDL_SetError("No hardware accelerated renderers available");
298 }
299
300 /* Create the data after we successfully create the renderer (bug #1116) */
301 data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data));
302 if (!data) {
303 SDL_DestroyRenderer(renderer);
304 return SDL_OutOfMemory();
305 }
306 SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data);
307
308 data->renderer = renderer;
309 }
310
311 /* Free any old texture and pixel data */
312 if (data->texture) {
313 SDL_DestroyTexture(data->texture);
314 data->texture = NULL;
315 }

Callers

nothing calls this directly

Calls 15

SDL_GetWindowDataFunction · 0.85
SDL_GetHintFunction · 0.85
SDL_strcasecmpFunction · 0.85
SDL_GetNumRenderDriversFunction · 0.85
SDL_GetRenderDriverInfoFunction · 0.85
SDL_CreateRendererFunction · 0.85
SDL_strcmpFunction · 0.85
SDL_SetErrorFunction · 0.85
SDL_callocFunction · 0.85
SDL_DestroyRendererFunction · 0.85
SDL_SetWindowDataFunction · 0.85
SDL_DestroyTextureFunction · 0.85

Tested by

no test coverage detected