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

Function SDL_CreateTexture

deps/SDL2/src/render/SDL_render.c:1042–1139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1040}
1041
1042SDL_Texture *
1043SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int h)
1044{
1045 SDL_Texture *texture;
1046
1047 CHECK_RENDERER_MAGIC(renderer, NULL);
1048
1049 if (!format) {
1050 format = renderer->info.texture_formats[0];
1051 }
1052 if (SDL_BYTESPERPIXEL(format) == 0) {
1053 SDL_SetError("Invalid texture format");
1054 return NULL;
1055 }
1056 if (SDL_ISPIXELFORMAT_INDEXED(format)) {
1057 SDL_SetError("Palettized textures are not supported");
1058 return NULL;
1059 }
1060 if (w <= 0 || h <= 0) {
1061 SDL_SetError("Texture dimensions can't be 0");
1062 return NULL;
1063 }
1064 if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) ||
1065 (renderer->info.max_texture_height && h > renderer->info.max_texture_height)) {
1066 SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height);
1067 return NULL;
1068 }
1069 texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
1070 if (!texture) {
1071 SDL_OutOfMemory();
1072 return NULL;
1073 }
1074 texture->magic = &texture_magic;
1075 texture->format = format;
1076 texture->access = access;
1077 texture->w = w;
1078 texture->h = h;
1079 texture->r = 255;
1080 texture->g = 255;
1081 texture->b = 255;
1082 texture->a = 255;
1083 texture->scaleMode = SDL_GetScaleMode();
1084 texture->renderer = renderer;
1085 texture->next = renderer->textures;
1086 if (renderer->textures) {
1087 renderer->textures->prev = texture;
1088 }
1089 renderer->textures = texture;
1090
1091 if (IsSupportedFormat(renderer, format)) {
1092 if (renderer->CreateTexture(renderer, texture) < 0) {
1093 SDL_DestroyTexture(texture);
1094 return NULL;
1095 }
1096 } else {
1097 texture->native = SDL_CreateTexture(renderer,
1098 GetClosestSupportedFormat(renderer, format),
1099 access, w, h);

Callers 10

mainFunction · 0.85
DrawFunction · 0.85
mainFunction · 0.85
unifont_load_textureFunction · 0.85
mainFunction · 0.85
DrawCompositeFunction · 0.85
DrawFunction · 0.85
mainFunction · 0.85
SDL_CreateWindowTextureFunction · 0.85

Calls 8

SDL_SetErrorFunction · 0.85
SDL_callocFunction · 0.85
SDL_GetScaleModeFunction · 0.85
IsSupportedFormatFunction · 0.85
SDL_DestroyTextureFunction · 0.85
SDL_SW_CreateYUVTextureFunction · 0.85
CreateTextureMethod · 0.45

Tested by 8

mainFunction · 0.68
DrawFunction · 0.68
mainFunction · 0.68
unifont_load_textureFunction · 0.68
mainFunction · 0.68
DrawCompositeFunction · 0.68
DrawFunction · 0.68
mainFunction · 0.68