Update SDLTexture backend
This commit is contained in:
parent
37a1518056
commit
f55c965a70
1 changed files with 3 additions and 20 deletions
|
@ -228,32 +228,17 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
|
|||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const unsigned char *src_pixel = surface->pixels;
|
||||
const unsigned char *src_pixel = pixels;
|
||||
|
||||
// Convert the colour-keyed pixels to RGBA32
|
||||
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};
|
||||
|
||||
if (SDL_UpdateTexture(surface->texture, &rect, buffer, width * 4) < 0)
|
||||
|
|
Loading…
Add table
Reference in a new issue