Change the renderer backend API for uploading pixels
Also fix some blatant build errors. I must be going mad - I swear I've fixed that typedef thing like twice already.
This commit is contained in:
parent
2fe0c44971
commit
74c9931ebb
5 changed files with 40 additions and 36 deletions
|
@ -13,7 +13,8 @@ void Backend_Deinit(void);
|
|||
void Backend_DrawScreen(void);
|
||||
Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height);
|
||||
void Backend_FreeSurface(Backend_Surface *surface);
|
||||
void Backend_LoadPixels(Backend_Surface *surface, const unsigned char *pixels, unsigned int width, unsigned int height, unsigned int pitch);
|
||||
unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch);
|
||||
void Backend_Unlock(Backend_Surface *surface);
|
||||
void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key);
|
||||
void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key);
|
||||
void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue);
|
||||
|
|
|
@ -82,15 +82,15 @@ void Backend_FreeSurface(Backend_Surface *surface)
|
|||
free(surface);
|
||||
}
|
||||
|
||||
void Backend_LoadPixels(Backend_Surface *surface, const unsigned char *pixels, unsigned int width, unsigned int height, unsigned int pitch)
|
||||
unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch)
|
||||
{
|
||||
for (unsigned int i = 0; i < height; ++i)
|
||||
{
|
||||
const unsigned char *src_row = &pixels[i * pitch];
|
||||
unsigned char *dst_row = (unsigned char*)surface->sdl_surface->pixels + i * surface->sdl_surface->pitch;
|
||||
*pitch = surface->sdl_surface->pitch;
|
||||
return (unsigned char*)surface->sdl_surface->pixels;
|
||||
}
|
||||
|
||||
memcpy(dst_row, src_row, width * 3);
|
||||
}
|
||||
void Backend_Unlock(Backend_Surface *surface)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key)
|
||||
|
|
|
@ -34,7 +34,7 @@ static void FlushSurface(Backend_Surface *surface)
|
|||
{
|
||||
unsigned char *src_pixel = (unsigned char*)surface->sdl_surface->pixels + (y * surface->sdl_surface->pitch);
|
||||
|
||||
for (int x = 0; x < surface->sdl_surface->x; ++x)
|
||||
for (int x = 0; x < surface->sdl_surface->w; ++x)
|
||||
{
|
||||
*buffer_pointer++ = src_pixel[0];
|
||||
*buffer_pointer++ = src_pixel[1];
|
||||
|
@ -146,16 +146,14 @@ void Backend_FreeSurface(Backend_Surface *surface)
|
|||
free(surface);
|
||||
}
|
||||
|
||||
void Backend_LoadPixels(Backend_Surface *surface, const unsigned char *pixels, unsigned int width, unsigned int height, unsigned int pitch)
|
||||
unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch)
|
||||
{
|
||||
for (unsigned int i = 0; i < height; ++i)
|
||||
{
|
||||
const unsigned char *src_row = &pixels[i * pitch];
|
||||
unsigned char *dst_row = (unsigned char*)surface->sdl_surface->pixels + i * surface->sdl_surface->pitch;
|
||||
|
||||
memcpy(dst_row, src_row, width * 3);
|
||||
}
|
||||
*pitch = surface->sdl_surface->pitch;
|
||||
return (unsigned char*)surface->sdl_surface->pixels;
|
||||
}
|
||||
|
||||
void Backend_Unlock(Backend_Surface *surface)
|
||||
{
|
||||
surface->needs_syncing = TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "../../Font.h"
|
||||
|
||||
struct Backend_Surface
|
||||
typedef struct Backend_Surface
|
||||
{
|
||||
unsigned char *pixels;
|
||||
unsigned int width;
|
||||
|
@ -81,15 +81,15 @@ void Backend_FreeSurface(Backend_Surface *surface)
|
|||
free(surface);
|
||||
}
|
||||
|
||||
void Backend_LoadPixels(Backend_Surface *surface, const unsigned char *pixels, unsigned int width, unsigned int height, unsigned int pitch)
|
||||
unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch)
|
||||
{
|
||||
for (unsigned int i = 0; i < height; ++i)
|
||||
{
|
||||
const unsigned char *src_row = &pixels[i * pitch];
|
||||
unsigned char *dst_row = &surface->pixels[i * surface->pitch];
|
||||
*pitch = surface->pitch;
|
||||
return surface->pixels;
|
||||
}
|
||||
|
||||
memcpy(dst_row, src_row, width * 3);
|
||||
}
|
||||
void Backend_Unlock(Backend_Surface *surface)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key)
|
||||
|
|
27
src/Draw.cpp
27
src/Draw.cpp
|
@ -211,25 +211,32 @@ static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface)
|
|||
else
|
||||
{
|
||||
// IF YOU WANT TO ADD HD SPRITES, THIS IS THE CODE YOU SHOULD EDIT
|
||||
unsigned int pitch;
|
||||
unsigned char *pixels = Backend_Lock(surf[surf_no].backend, &pitch);
|
||||
|
||||
if (magnification == 1)
|
||||
{
|
||||
// Just copy the pixels the way they are
|
||||
Backend_LoadPixels(surf[surf_no].backend, (unsigned char*)converted_surface->pixels, converted_surface->w, converted_surface->h, converted_surface->pitch);
|
||||
for (int y = 0; y < converted_surface->h; ++y)
|
||||
{
|
||||
const unsigned char *src_row = (unsigned char*)converted_surface->pixels + y * converted_surface->pitch;
|
||||
unsigned char *dst_row = &pixels[y * pitch];
|
||||
|
||||
memcpy(dst_row, src_row, converted_surface->w * 3);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Upscale the bitmap to the game's internal resolution
|
||||
unsigned char *pixels = (unsigned char*)malloc((converted_surface->w * magnification) * (converted_surface->h * magnification) * 3);
|
||||
|
||||
for (int h = 0; h < converted_surface->h; ++h)
|
||||
for (int y = 0; y < converted_surface->h; ++y)
|
||||
{
|
||||
const unsigned char *src_row = (unsigned char*)converted_surface->pixels + h * converted_surface->pitch;
|
||||
unsigned char *dst_row = pixels + h * (converted_surface->w * magnification * 3) * magnification;
|
||||
const unsigned char *src_row = (unsigned char*)converted_surface->pixels + y * converted_surface->pitch;
|
||||
unsigned char *dst_row = &pixels[y * pitch * magnification];
|
||||
|
||||
const unsigned char *src_ptr = src_row;
|
||||
unsigned char *dst_ptr = dst_row;
|
||||
|
||||
for (int w = 0; w < converted_surface->w; ++w)
|
||||
for (int x = 0; x < converted_surface->w; ++x)
|
||||
{
|
||||
for (int i = 0; i < magnification; ++i)
|
||||
{
|
||||
|
@ -242,13 +249,11 @@ static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface)
|
|||
}
|
||||
|
||||
for (int i = 1; i < magnification; ++i)
|
||||
memcpy(dst_row + i * converted_surface->w * magnification * 3, dst_row, converted_surface->w * magnification * 3);
|
||||
memcpy(dst_row + i * pitch, dst_row, converted_surface->w * magnification * 3);
|
||||
}
|
||||
|
||||
Backend_LoadPixels(surf[surf_no].backend, pixels, converted_surface->w * magnification, converted_surface->h * magnification, converted_surface->w * magnification * 3);
|
||||
free(pixels);
|
||||
}
|
||||
|
||||
Backend_Unlock(surf[surf_no].backend);
|
||||
SDL_FreeSurface(converted_surface);
|
||||
printf(" ^ Successfully loaded\n");
|
||||
success = TRUE;
|
||||
|
|
Loading…
Add table
Reference in a new issue