Update SDLTexture backend

This commit is contained in:
Clownacy 2020-09-14 23:09:55 +01:00
parent 37a1518056
commit f55c965a70

View file

@ -228,32 +228,17 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
surface->lost = false; surface->lost = false;
} }
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height) void RenderBackend_UploadSurface(RenderBackend_Surface *surface, const unsigned char *pixels, size_t width, size_t height)
{ {
if (surface == NULL)
return NULL;
*pitch = width * 3;
surface->pixels = (unsigned char*)malloc(width * height * 3);
return surface->pixels;
}
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
{
if (surface == NULL)
return;
unsigned char *buffer = (unsigned char*)malloc(width * height * 4); unsigned char *buffer = (unsigned char*)malloc(width * height * 4);
if (buffer == NULL) if (buffer == NULL)
{ {
Backend_PrintError("Couldn't allocate memory for surface buffer: %s", SDL_GetError()); Backend_PrintError("Couldn't allocate memory for surface buffer");
return; return;
} }
const unsigned char *src_pixel = surface->pixels; const unsigned char *src_pixel = pixels;
// Convert the colour-keyed pixels to RGBA32 // Convert the colour-keyed pixels to RGBA32
for (size_t y = 0; y < height; ++y) for (size_t y = 0; y < height; ++y)
@ -275,8 +260,6 @@ void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, s
} }
} }
free(surface->pixels);
SDL_Rect rect = {0, 0, (int)width, (int)height}; SDL_Rect rect = {0, 0, (int)width, (int)height};
if (SDL_UpdateTexture(surface->texture, &rect, buffer, width * 4) < 0) if (SDL_UpdateTexture(surface->texture, &rect, buffer, width * 4) < 0)