/* * SDL.createRGBSurfaceWithFormat( * width, * height, * depth = 32, * format = SDL.pixelFormat.RGBA32) * * Create a surface object with the specified format and return it. * * Returns: * The surface or nil * The error message */ static int l_surface_createRGBWithFormat(lua_State *L) { int width = luaL_checkinteger(L, 1); int height = luaL_checkinteger(L, 2); int depth = luaL_optinteger(L, 3, 32); int format = luaL_optinteger(L, 4, SDL_PIXELFORMAT_RGBA32); SDL_Surface *s; s = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth, format); if (s == NULL) return commonPushSDLError(L, 1); return commonPush(L, "p", SurfaceName, s); }
// // SDLVideoDriver::SetPrimaryBuffer // // Create a software surface for the game engine to render frames into and // set it to video.screens[0]. // void SDLVideoDriver::SetPrimaryBuffer() { int bump = (video.width == 512 || video.width == 1024) ? 4 : 0; if(window) { // SDL_FIXME: This won't be sufficient once a truecolour renderer is implemented primary_surface = SDL_CreateRGBSurfaceWithFormat(0, video.width + bump, video.height, 0, SDL_PIXELFORMAT_INDEX8); if(!primary_surface) I_Error("SDLVideoDriver::SetPrimaryBuffer: failed to create screen temp buffer\n"); Uint32 pixelformat = SDL_GetWindowPixelFormat(window); if(pixelformat == SDL_PIXELFORMAT_UNKNOWN) pixelformat = SDL_PIXELFORMAT_RGBA32; rgba_surface = SDL_CreateRGBSurfaceWithFormat(0, video.width + bump, video.height, 0, pixelformat); if(!rgba_surface) { I_Error("SDLVideoDriver::SetPrimaryBuffer: failed to create true-colour buffer: %s\n", SDL_GetError()); } sdltexture = SDL_CreateTexture(renderer, pixelformat, SDL_TEXTUREACCESS_STREAMING, video.width + bump, video.height); if(!sdltexture) { I_Error("SDLVideoDriver::SetPrimaryBuffer: failed to create rendering texture: %s\n", SDL_GetError()); } video.screens[0] = static_cast<byte *>(primary_surface->pixels); video.pitch = primary_surface->pitch; } }
/* * Create an empty RGB surface of the appropriate depth */ SDL_Surface * SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) { Uint32 format; /* Get the pixel format */ format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask); if (format == SDL_PIXELFORMAT_UNKNOWN) { SDL_SetError("Unknown pixel format"); return NULL; } return SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format); }
/* * Create an RGB surface from an existing memory buffer using the given given * enum SDL_PIXELFORMAT_* format */ SDL_Surface * SDL_CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 format) { SDL_Surface *surface; surface = SDL_CreateRGBSurfaceWithFormat(0, 0, 0, depth, format); if (surface != NULL) { surface->flags |= SDL_PREALLOC; surface->pixels = pixels; surface->w = width; surface->h = height; surface->pitch = pitch; SDL_SetClipRect(surface, NULL); } return surface; }
SDL_Surface *Surface::createSurfaceWithFormat(int width, int height, int depth, uint32_t format) { #if SDL_VERSION_ATLEAST(2, 0, 5) return SDL_CreateRGBSurfaceWithFormat(0, width, height, depth, format); #else SDL_Surface *unoptSurface = SDL_CreateRGBSurface(0, width, height, depth, 0, 0, 0, 0); SDL_Surface *optSurface = SDL_ConvertSurfaceFormat(unoptSurface, format, 0); SDL_FreeSurface(unoptSurface); // Surfaces with alpha are set up for blending by default. if (optSurface->format->Amask != 0) { SDL_SetSurfaceBlendMode(optSurface, SDL_BLENDMODE_BLEND); } return optSurface; #endif }