Convert a bunch of ints to size_t
ints are dumb - only use them when you have to
This commit is contained in:
parent
8ad56ced43
commit
988f1128dd
20 changed files with 104 additions and 96 deletions
|
@ -13,15 +13,15 @@ typedef struct RenderBackend_Rect
|
|||
long bottom;
|
||||
} RenderBackend_Rect;
|
||||
|
||||
RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen);
|
||||
RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen);
|
||||
void RenderBackend_Deinit(void);
|
||||
void RenderBackend_DrawScreen(void);
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target);
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target);
|
||||
void RenderBackend_FreeSurface(RenderBackend_Surface *surface);
|
||||
bool RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface);
|
||||
void RenderBackend_RestoreSurface(RenderBackend_Surface *surface);
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height);
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height);
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height);
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height);
|
||||
void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key);
|
||||
void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RenderBackend_Rect *rect, unsigned char red, unsigned char green, unsigned char blue);
|
||||
RenderBackend_GlyphAtlas* RenderBackend_CreateGlyphAtlas(size_t size);
|
||||
|
@ -31,4 +31,4 @@ void RenderBackend_PrepareToDrawGlyphs(RenderBackend_GlyphAtlas *atlas, RenderBa
|
|||
void RenderBackend_DrawGlyph(RenderBackend_GlyphAtlas *atlas, long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height);
|
||||
void RenderBackend_FlushGlyphs(void);
|
||||
void RenderBackend_HandleRenderTargetLoss(void);
|
||||
void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height);
|
||||
void RenderBackend_HandleWindowResize(size_t width, size_t height);
|
||||
|
|
|
@ -32,8 +32,8 @@ typedef enum RenderMode
|
|||
typedef struct RenderBackend_Surface
|
||||
{
|
||||
GLuint texture_id;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
size_t width;
|
||||
size_t height;
|
||||
unsigned char *pixels;
|
||||
} RenderBackend_Surface;
|
||||
|
||||
|
@ -75,8 +75,8 @@ static GLuint vertex_buffer_ids[TOTAL_VBOS];
|
|||
static GLuint framebuffer_id;
|
||||
|
||||
static VertexBufferSlot *local_vertex_buffer;
|
||||
static unsigned long local_vertex_buffer_size;
|
||||
static unsigned long current_vertex_buffer_slot;
|
||||
static size_t local_vertex_buffer_size;
|
||||
static size_t current_vertex_buffer_slot;
|
||||
|
||||
static RenderMode last_render_mode;
|
||||
static GLuint last_source_texture;
|
||||
|
@ -86,8 +86,8 @@ static RenderBackend_Surface framebuffer;
|
|||
|
||||
static RenderBackend_Surface *glyph_destination_surface;
|
||||
|
||||
static int actual_screen_width;
|
||||
static int actual_screen_height;
|
||||
static size_t actual_screen_width;
|
||||
static size_t actual_screen_height;
|
||||
|
||||
#ifdef USE_OPENGLES2
|
||||
static const GLchar *vertex_shader_plain = " \
|
||||
|
@ -337,8 +337,8 @@ static VertexBufferSlot* GetVertexBufferSlot(unsigned int slots_needed)
|
|||
|
||||
static void FlushVertexBuffer(void)
|
||||
{
|
||||
static unsigned long vertex_buffer_size[TOTAL_VBOS];
|
||||
static unsigned int current_vertex_buffer = 0;
|
||||
static size_t vertex_buffer_size[TOTAL_VBOS];
|
||||
static size_t current_vertex_buffer = 0;
|
||||
|
||||
if (current_vertex_buffer_slot == 0)
|
||||
return;
|
||||
|
@ -425,7 +425,7 @@ static void PostGLCallCallback(const char *name, void *function_pointer, int len
|
|||
// Render-backend initialisation //
|
||||
///////////////////////////////////
|
||||
|
||||
RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
|
||||
RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
|
||||
{
|
||||
#ifndef USE_OPENGLES2
|
||||
glad_set_post_callback(PostGLCallCallback);
|
||||
|
@ -637,7 +637,7 @@ void RenderBackend_DrawScreen(void)
|
|||
// Surface management //
|
||||
////////////////////////
|
||||
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target)
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
|
||||
{
|
||||
(void)render_target;
|
||||
|
||||
|
@ -695,7 +695,7 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
|
|||
(void)surface;
|
||||
}
|
||||
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height)
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height)
|
||||
{
|
||||
if (surface == NULL)
|
||||
return NULL;
|
||||
|
@ -705,7 +705,7 @@ unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigne
|
|||
return surface->pixels;
|
||||
}
|
||||
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height)
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
|
||||
{
|
||||
if (surface == NULL)
|
||||
return;
|
||||
|
@ -1021,7 +1021,7 @@ void RenderBackend_HandleRenderTargetLoss(void)
|
|||
// No problem for us
|
||||
}
|
||||
|
||||
void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height)
|
||||
void RenderBackend_HandleWindowResize(size_t width, size_t height)
|
||||
{
|
||||
actual_screen_width = width;
|
||||
actual_screen_height = height;
|
||||
|
|
|
@ -42,7 +42,7 @@ static void RectToSDLRect(const RenderBackend_Rect *rect, SDL_Rect *sdl_rect)
|
|||
sdl_rect->h = 0;
|
||||
}
|
||||
|
||||
RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
|
||||
RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
|
||||
{
|
||||
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
|
||||
|
||||
|
@ -100,7 +100,7 @@ void RenderBackend_DrawScreen(void)
|
|||
Backend_PrintError("Couldn't put window surface on screen: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target)
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
|
||||
{
|
||||
(void)render_target;
|
||||
|
||||
|
@ -141,7 +141,7 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
|
|||
(void)surface;
|
||||
}
|
||||
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height)
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height)
|
||||
{
|
||||
(void)width;
|
||||
(void)height;
|
||||
|
@ -155,7 +155,7 @@ unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigne
|
|||
return (unsigned char*)surface->sdlsurface->pixels;
|
||||
}
|
||||
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height)
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
|
||||
{
|
||||
(void)width;
|
||||
(void)height;
|
||||
|
@ -287,7 +287,7 @@ void RenderBackend_HandleRenderTargetLoss(void)
|
|||
// No problem for us
|
||||
}
|
||||
|
||||
void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height)
|
||||
void RenderBackend_HandleWindowResize(size_t width, size_t height)
|
||||
{
|
||||
(void)width;
|
||||
(void)height;
|
||||
|
|
|
@ -16,8 +16,8 @@ typedef struct RenderBackend_Surface
|
|||
{
|
||||
SDL_Texture *texture;
|
||||
unsigned char *pixels;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
size_t width;
|
||||
size_t height;
|
||||
bool lost;
|
||||
|
||||
struct RenderBackend_Surface *next;
|
||||
|
@ -51,7 +51,7 @@ static void RectToSDLRect(const RenderBackend_Rect *rect, SDL_Rect *sdl_rect)
|
|||
sdl_rect->h = 0;
|
||||
}
|
||||
|
||||
RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
|
||||
RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
|
||||
{
|
||||
Backend_PrintInfo("Available SDL render drivers:");
|
||||
|
||||
|
@ -141,7 +141,7 @@ void RenderBackend_DrawScreen(void)
|
|||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target)
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
|
||||
{
|
||||
RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface));
|
||||
|
||||
|
@ -196,7 +196,7 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
|
|||
surface->lost = false;
|
||||
}
|
||||
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height)
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height)
|
||||
{
|
||||
if (surface == NULL)
|
||||
return NULL;
|
||||
|
@ -208,7 +208,7 @@ unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigne
|
|||
return surface->pixels;
|
||||
}
|
||||
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height)
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
|
||||
{
|
||||
if (surface == NULL)
|
||||
return;
|
||||
|
@ -224,11 +224,11 @@ void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int wi
|
|||
const unsigned char *src_pixel = surface->pixels;
|
||||
|
||||
// Convert the SDL_Surface's colour-keyed pixels to RGBA32
|
||||
for (unsigned int y = 0; y < height; ++y)
|
||||
for (size_t y = 0; y < height; ++y)
|
||||
{
|
||||
unsigned char *buffer_pointer = &buffer[y * width * 4];
|
||||
|
||||
for (unsigned int x = 0; x < width; ++x)
|
||||
for (size_t x = 0; x < width; ++x)
|
||||
{
|
||||
*buffer_pointer++ = src_pixel[0];
|
||||
*buffer_pointer++ = src_pixel[1];
|
||||
|
@ -413,7 +413,7 @@ void RenderBackend_HandleRenderTargetLoss(void)
|
|||
surface->lost = true;
|
||||
}
|
||||
|
||||
void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height)
|
||||
void RenderBackend_HandleWindowResize(size_t width, size_t height)
|
||||
{
|
||||
(void)width;
|
||||
(void)height;
|
||||
|
|
|
@ -30,7 +30,7 @@ static RenderBackend_Surface framebuffer;
|
|||
static unsigned char glyph_colour_channels[3];
|
||||
static RenderBackend_Surface *glyph_destination_surface;
|
||||
|
||||
RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
|
||||
RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
|
||||
{
|
||||
if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen))
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ void RenderBackend_DrawScreen(void)
|
|||
framebuffer.pixels = WindowBackend_Software_LockFramebuffer(&framebuffer.pitch);
|
||||
}
|
||||
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target)
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
|
||||
{
|
||||
(void)render_target;
|
||||
|
||||
|
@ -107,7 +107,7 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
|
|||
(void)surface;
|
||||
}
|
||||
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height)
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height)
|
||||
{
|
||||
(void)width;
|
||||
(void)height;
|
||||
|
@ -119,7 +119,7 @@ unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigne
|
|||
return surface->pixels;
|
||||
}
|
||||
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height)
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
|
||||
{
|
||||
(void)surface;
|
||||
(void)width;
|
||||
|
@ -334,7 +334,7 @@ void RenderBackend_HandleRenderTargetLoss(void)
|
|||
// No problem for us
|
||||
}
|
||||
|
||||
void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height)
|
||||
void RenderBackend_HandleWindowResize(size_t width, size_t height)
|
||||
{
|
||||
WindowBackend_Software_HandleWindowResize(width, height);
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ typedef struct RenderBackend_Surface
|
|||
{
|
||||
GX2Texture texture;
|
||||
GX2ColorBuffer colour_buffer;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
size_t width;
|
||||
size_t height;
|
||||
bool render_target;
|
||||
unsigned char *lock_buffer; // TODO - Dumb
|
||||
} RenderBackend_Surface;
|
||||
|
@ -93,8 +93,8 @@ static Viewport tv_viewport;
|
|||
static Viewport drc_viewport;
|
||||
|
||||
static VertexBufferSlot *local_vertex_buffer;
|
||||
static unsigned long local_vertex_buffer_size;
|
||||
static unsigned long current_vertex_buffer_slot;
|
||||
static size_t local_vertex_buffer_size;
|
||||
static size_t current_vertex_buffer_slot;
|
||||
|
||||
static RenderMode last_render_mode;
|
||||
static GX2Texture *last_source_texture;
|
||||
|
@ -130,8 +130,8 @@ static VertexBufferSlot* GetVertexBufferSlot(void)
|
|||
|
||||
static void FlushVertexBuffer(void)
|
||||
{
|
||||
static unsigned long vertex_buffer_size;
|
||||
static unsigned int current_vertex_buffer = 0;
|
||||
static size_t vertex_buffer_size;
|
||||
static size_t current_vertex_buffer = 0;
|
||||
|
||||
if (current_vertex_buffer_slot == 0)
|
||||
return;
|
||||
|
@ -176,7 +176,7 @@ static void FlushVertexBuffer(void)
|
|||
current_vertex_buffer_slot = 0;
|
||||
}
|
||||
|
||||
static void CalculateViewport(unsigned int actual_screen_width, unsigned int actual_screen_height, Viewport *viewport)
|
||||
static void CalculateViewport(size_t actual_screen_width, size_t actual_screen_height, Viewport *viewport)
|
||||
{
|
||||
if ((float)actual_screen_width / (float)actual_screen_height > (float)framebuffer_surface->width / (float)framebuffer_surface->height)
|
||||
{
|
||||
|
@ -449,7 +449,7 @@ void RenderBackend_DrawScreen(void)
|
|||
GX2SetContextState(gx2_context);
|
||||
}
|
||||
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target)
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
|
||||
{
|
||||
RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface));
|
||||
|
||||
|
@ -539,7 +539,7 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
|
|||
(void)surface;
|
||||
}
|
||||
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height)
|
||||
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height)
|
||||
{
|
||||
if (surface != NULL)
|
||||
{
|
||||
|
@ -554,7 +554,7 @@ unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigne
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height)
|
||||
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
|
||||
{
|
||||
if (surface != NULL)
|
||||
{
|
||||
|
@ -884,7 +884,7 @@ void RenderBackend_HandleRenderTargetLoss(void)
|
|||
// Doesn't happen on the Wii U
|
||||
}
|
||||
|
||||
void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height)
|
||||
void RenderBackend_HandleWindowResize(size_t width, size_t height)
|
||||
{
|
||||
(void)width;
|
||||
(void)height;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
bool WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, bool fullscreen);
|
||||
#include <stddef.h>
|
||||
|
||||
bool WindowBackend_OpenGL_CreateWindow(const char *window_title, size_t *screen_width, size_t *screen_height, bool fullscreen);
|
||||
void WindowBackend_OpenGL_DestroyWindow(void);
|
||||
void WindowBackend_OpenGL_Display(void);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
GLFWwindow *window;
|
||||
|
||||
bool WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, bool fullscreen)
|
||||
bool WindowBackend_OpenGL_CreateWindow(const char *window_title, size_t *screen_width, size_t *screen_height, bool fullscreen)
|
||||
{
|
||||
#ifdef USE_OPENGLES2
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
|
|
|
@ -15,7 +15,7 @@ SDL_Window *window;
|
|||
|
||||
static SDL_GLContext context;
|
||||
|
||||
bool WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, bool fullscreen)
|
||||
bool WindowBackend_OpenGL_CreateWindow(const char *window_title, size_t *screen_width, size_t *screen_height, bool fullscreen)
|
||||
{
|
||||
#ifdef USE_OPENGLES2
|
||||
if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES) < 0)
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen);
|
||||
bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen);
|
||||
void WindowBackend_Software_DestroyWindow(void);
|
||||
unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch);
|
||||
void WindowBackend_Software_UnlockFramebuffer(void);
|
||||
void WindowBackend_Software_Display(void);
|
||||
void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height);
|
||||
void WindowBackend_Software_HandleWindowResize(size_t width, size_t height);
|
||||
|
|
|
@ -11,15 +11,15 @@
|
|||
GLFWwindow *window;
|
||||
|
||||
static unsigned char *framebuffer;
|
||||
static int framebuffer_width;
|
||||
static int framebuffer_height;
|
||||
static size_t framebuffer_width;
|
||||
static size_t framebuffer_height;
|
||||
|
||||
static float framebuffer_x_ratio;
|
||||
static float framebuffer_y_ratio;
|
||||
|
||||
static GLuint screen_texture_id;
|
||||
|
||||
bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen)
|
||||
bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
|
||||
{
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
|
||||
|
@ -59,11 +59,11 @@ bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_wi
|
|||
glGenTextures(1, &screen_texture_id);
|
||||
glBindTexture(GL_TEXTURE_2D, screen_texture_id);
|
||||
|
||||
int framebuffer_texture_width = 1;
|
||||
size_t framebuffer_texture_width = 1;
|
||||
while (framebuffer_texture_width < framebuffer_width)
|
||||
framebuffer_texture_width <<= 1;
|
||||
|
||||
int framebuffer_texture_height = 1;
|
||||
size_t framebuffer_texture_height = 1;
|
||||
while (framebuffer_texture_height < framebuffer_height)
|
||||
framebuffer_texture_height <<= 1;
|
||||
|
||||
|
@ -127,7 +127,7 @@ void WindowBackend_Software_Display(void)
|
|||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height)
|
||||
void WindowBackend_Software_HandleWindowResize(size_t width, size_t height)
|
||||
{
|
||||
// Do some viewport trickery, to fit the framebuffer in the center of the screen
|
||||
GLint viewport_x;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
static unsigned char *framebuffer;
|
||||
static size_t framebuffer_pitch;
|
||||
|
||||
bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen)
|
||||
bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
|
||||
{
|
||||
(void)window_title;
|
||||
(void)fullscreen;
|
||||
|
@ -45,7 +45,7 @@ void WindowBackend_Software_Display(void)
|
|||
|
||||
}
|
||||
|
||||
void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height)
|
||||
void WindowBackend_Software_HandleWindowResize(size_t width, size_t height)
|
||||
{
|
||||
(void)width;
|
||||
(void)height;
|
||||
|
|
|
@ -13,7 +13,7 @@ SDL_Window *window;
|
|||
static SDL_Surface *window_sdlsurface;
|
||||
static SDL_Surface *framebuffer_sdlsurface;
|
||||
|
||||
bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen)
|
||||
bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
|
||||
{
|
||||
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
|
||||
|
||||
|
@ -88,7 +88,7 @@ void WindowBackend_Software_Display(void)
|
|||
Backend_PrintError("Couldn't copy window surface to the screen: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height)
|
||||
void WindowBackend_Software_HandleWindowResize(size_t width, size_t height)
|
||||
{
|
||||
(void)width;
|
||||
(void)height;
|
||||
|
|
|
@ -48,7 +48,7 @@ static GX2Texture screen_texture;
|
|||
static Viewport tv_viewport;
|
||||
static Viewport drc_viewport;
|
||||
|
||||
static void CalculateViewport(unsigned int actual_screen_width, unsigned int actual_screen_height, Viewport *viewport)
|
||||
static void CalculateViewport(size_t actual_screen_width, size_t actual_screen_height, Viewport *viewport)
|
||||
{
|
||||
if (actual_screen_width * fake_framebuffer_height > fake_framebuffer_width * actual_screen_height) // Fancy way to do `if (actual_screen_width / actual_screen_height > fake_framebuffer_width / fake_framebuffer_height)` without floats
|
||||
{
|
||||
|
@ -68,7 +68,7 @@ static void CalculateViewport(unsigned int actual_screen_width, unsigned int act
|
|||
}
|
||||
}
|
||||
|
||||
bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen)
|
||||
bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
|
||||
{
|
||||
(void)window_title;
|
||||
(void)fullscreen;
|
||||
|
@ -265,7 +265,7 @@ ATTRIBUTE_HOT void WindowBackend_Software_Display(void)
|
|||
WHBGfxFinishRender();
|
||||
}
|
||||
|
||||
void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height)
|
||||
void WindowBackend_Software_HandleWindowResize(size_t width, size_t height)
|
||||
{
|
||||
(void)width;
|
||||
(void)height;
|
||||
|
|
|
@ -12,19 +12,25 @@
|
|||
|
||||
#include "File.h"
|
||||
|
||||
unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, unsigned int *width, unsigned int *height)
|
||||
unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, size_t *width, size_t *height)
|
||||
{
|
||||
return stbi_load_from_memory(in_buffer, in_buffer_size, (int*)width, (int*)height, NULL, 3);
|
||||
int int_width, int_height;
|
||||
unsigned char *image_buffer = stbi_load_from_memory(in_buffer, in_buffer_size, &int_width, &int_height, NULL, 3);
|
||||
|
||||
*width = int_width;
|
||||
*height = int_height;
|
||||
|
||||
return image_buffer;
|
||||
}
|
||||
|
||||
unsigned char* DecodeBitmapFromFile(const char *path, unsigned int *width, unsigned int *height)
|
||||
unsigned char* DecodeBitmapFromFile(const char *path, size_t *width, size_t *height)
|
||||
{
|
||||
size_t file_size;
|
||||
unsigned char *file_buffer = LoadFileToMemory(path, &file_size);
|
||||
|
||||
if (file_buffer != NULL)
|
||||
{
|
||||
unsigned char *image_buffer = stbi_load_from_memory(file_buffer, file_size, (int*)width, (int*)height, NULL, 3);
|
||||
unsigned char *image_buffer = DecodeBitmap(file_buffer, file_size, width, height);
|
||||
|
||||
free(file_buffer);
|
||||
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, unsigned int *width, unsigned int *height);
|
||||
unsigned char* DecodeBitmapFromFile(const char *path, unsigned int *width, unsigned int *height);
|
||||
unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, size_t *width, size_t *height);
|
||||
unsigned char* DecodeBitmapFromFile(const char *path, size_t *width, size_t *height);
|
||||
void FreeBitmap(unsigned char *buffer);
|
||||
|
|
20
src/Draw.cpp
20
src/Draw.cpp
|
@ -147,10 +147,10 @@ void ReleaseSurface(SurfaceID s)
|
|||
memset(&surface_metadata[s], 0, sizeof(surface_metadata[0]));
|
||||
}
|
||||
|
||||
static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, int width, int height, SurfaceID surf_no)
|
||||
static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, size_t width, size_t height, SurfaceID surf_no)
|
||||
{
|
||||
// IF YOU WANT TO ADD HD SPRITES, THIS IS THE CODE YOU SHOULD EDIT
|
||||
unsigned int pitch;
|
||||
size_t pitch;
|
||||
unsigned char *pixels = RenderBackend_LockSurface(surf[surf_no], &pitch, width * mag, height * mag);
|
||||
|
||||
if (pixels == NULL)
|
||||
|
@ -159,7 +159,7 @@ static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, int width,
|
|||
if (mag == 1)
|
||||
{
|
||||
// Just copy the pixels the way they are
|
||||
for (int y = 0; y < height; ++y)
|
||||
for (size_t y = 0; y < height; ++y)
|
||||
{
|
||||
const unsigned char *src_row = &image_buffer[y * width * 3];
|
||||
unsigned char *dst_row = &pixels[y * pitch];
|
||||
|
@ -170,7 +170,7 @@ static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, int width,
|
|||
else
|
||||
{
|
||||
// Upscale the bitmap to the game's internal resolution
|
||||
for (int y = 0; y < height; ++y)
|
||||
for (size_t y = 0; y < height; ++y)
|
||||
{
|
||||
const unsigned char *src_row = &image_buffer[y * width * 3];
|
||||
unsigned char *dst_row = &pixels[y * pitch * mag];
|
||||
|
@ -178,7 +178,7 @@ static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, int width,
|
|||
const unsigned char *src_ptr = src_row;
|
||||
unsigned char *dst_ptr = dst_row;
|
||||
|
||||
for (int x = 0; x < width; ++x)
|
||||
for (size_t x = 0; x < width; ++x)
|
||||
{
|
||||
for (int i = 0; i < mag; ++i)
|
||||
{
|
||||
|
@ -215,7 +215,7 @@ BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no)
|
|||
if (data == NULL)
|
||||
return FALSE;
|
||||
|
||||
unsigned int width, height;
|
||||
size_t width, height;
|
||||
unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
|
||||
|
||||
if (image_buffer == NULL)
|
||||
|
@ -273,7 +273,7 @@ BOOL MakeSurface_File(const char *name, SurfaceID surf_no)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
unsigned int width, height;
|
||||
size_t width, height;
|
||||
unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height);
|
||||
|
||||
if (image_buffer == NULL)
|
||||
|
@ -319,7 +319,7 @@ BOOL ReloadBitmap_Resource(const char *name, SurfaceID surf_no)
|
|||
if (data == NULL)
|
||||
return FALSE;
|
||||
|
||||
unsigned int width, height;
|
||||
size_t width, height;
|
||||
unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
|
||||
|
||||
if (!ScaleAndUploadSurface(image_buffer, width, height, surf_no))
|
||||
|
@ -357,7 +357,7 @@ BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
unsigned int width, height;
|
||||
size_t width, height;
|
||||
unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height);
|
||||
|
||||
if (image_buffer == NULL)
|
||||
|
@ -647,7 +647,7 @@ void InitTextObject(const char *name)
|
|||
std::string path = gDataPath + "/Font/font";
|
||||
|
||||
// Get font size
|
||||
unsigned int width, height;
|
||||
size_t width, height;
|
||||
|
||||
switch (mag)
|
||||
{
|
||||
|
|
20
src/Font.cpp
20
src/Font.cpp
|
@ -842,7 +842,7 @@ static const unsigned short shiftjis_to_unicode_lookup[0x3100] = {
|
|||
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020
|
||||
};
|
||||
|
||||
static unsigned short ShiftJISToUnicode(const unsigned char *string, unsigned int *bytes_read)
|
||||
static unsigned short ShiftJISToUnicode(const unsigned char *string, size_t *bytes_read)
|
||||
{
|
||||
size_t lookup_index;
|
||||
|
||||
|
@ -875,9 +875,9 @@ static unsigned short ShiftJISToUnicode(const unsigned char *string, unsigned in
|
|||
|
||||
#else
|
||||
|
||||
static unsigned long UTF8ToUnicode(const unsigned char *string, unsigned int *bytes_read)
|
||||
static unsigned long UTF8ToUnicode(const unsigned char *string, size_t *bytes_read)
|
||||
{
|
||||
unsigned int length;
|
||||
size_t length;
|
||||
unsigned long charcode;
|
||||
|
||||
unsigned int zero_bit = 0;
|
||||
|
@ -1006,11 +1006,11 @@ static Glyph* GetGlyph(FontObject *font_object, unsigned long unicode_value)
|
|||
switch (font_object->face->glyph->bitmap.pixel_mode)
|
||||
{
|
||||
case FT_PIXEL_MODE_GRAY:
|
||||
for (unsigned int y = 0; y < bitmap.rows; ++y)
|
||||
for (size_t y = 0; y < bitmap.rows; ++y)
|
||||
{
|
||||
unsigned char *pixel_pointer = &bitmap.buffer[y * bitmap.pitch];
|
||||
|
||||
for (unsigned int x = 0; x < bitmap.width; ++x)
|
||||
for (size_t x = 0; x < bitmap.width; ++x)
|
||||
{
|
||||
*pixel_pointer = GammaCorrect((*pixel_pointer * 0xFF) / (bitmap.num_grays - 1));
|
||||
++pixel_pointer;
|
||||
|
@ -1020,11 +1020,11 @@ static Glyph* GetGlyph(FontObject *font_object, unsigned long unicode_value)
|
|||
break;
|
||||
|
||||
case FT_PIXEL_MODE_MONO:
|
||||
for (unsigned int y = 0; y < bitmap.rows; ++y)
|
||||
for (size_t y = 0; y < bitmap.rows; ++y)
|
||||
{
|
||||
unsigned char *pixel_pointer = &bitmap.buffer[y * bitmap.pitch];
|
||||
|
||||
for (unsigned int x = 0; x < bitmap.width; ++x)
|
||||
for (size_t x = 0; x < bitmap.width; ++x)
|
||||
{
|
||||
*pixel_pointer = *pixel_pointer ? 0xFF : 0;
|
||||
++pixel_pointer;
|
||||
|
@ -1058,7 +1058,7 @@ static Glyph* GetGlyph(FontObject *font_object, unsigned long unicode_value)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, unsigned int cell_width, unsigned int cell_height)
|
||||
FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, size_t cell_width, size_t cell_height)
|
||||
{
|
||||
FontObject *font_object = (FontObject*)malloc(sizeof(FontObject));
|
||||
|
||||
|
@ -1118,7 +1118,7 @@ FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, unsign
|
|||
return NULL;
|
||||
}
|
||||
|
||||
FontObject* LoadFont(const char *font_filename, unsigned int cell_width, unsigned int cell_height)
|
||||
FontObject* LoadFont(const char *font_filename, size_t cell_width, size_t cell_height)
|
||||
{
|
||||
FontObject *font_object = NULL;
|
||||
|
||||
|
@ -1149,7 +1149,7 @@ void DrawText(FontObject *font_object, RenderBackend_Surface *surface, int x, in
|
|||
|
||||
while (string_pointer != string_end)
|
||||
{
|
||||
unsigned int bytes_read;
|
||||
size_t bytes_read;
|
||||
#ifdef JAPANESE
|
||||
const unsigned short unicode_value = ShiftJISToUnicode(string_pointer, &bytes_read);
|
||||
#else
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
typedef struct FontObject FontObject;
|
||||
|
||||
FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, unsigned int cell_width, unsigned int cell_height);
|
||||
FontObject* LoadFont(const char *font_filename, unsigned int cell_width, unsigned int cell_height);
|
||||
FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, size_t cell_width, size_t cell_height);
|
||||
FontObject* LoadFont(const char *font_filename, size_t cell_width, size_t cell_height);
|
||||
void DrawText(FontObject *font_object, RenderBackend_Surface *surface, int x, int y, unsigned long colour, const char *string);
|
||||
void UnloadFont(FontObject *font_object);
|
||||
|
|
|
@ -294,7 +294,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (window_icon_resource_data != NULL)
|
||||
{
|
||||
unsigned int window_icon_width, window_icon_height;
|
||||
size_t window_icon_width, window_icon_height;
|
||||
unsigned char *window_icon_rgb_pixels = DecodeBitmap(window_icon_resource_data, window_icon_resource_size, &window_icon_width, &window_icon_height);
|
||||
|
||||
if (window_icon_rgb_pixels != NULL)
|
||||
|
@ -311,7 +311,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (cursor_resource_data != NULL)
|
||||
{
|
||||
unsigned int cursor_width, cursor_height;
|
||||
size_t cursor_width, cursor_height;
|
||||
unsigned char *cursor_rgb_pixels = DecodeBitmap(cursor_resource_data, cursor_resource_size, &cursor_width, &cursor_height);
|
||||
|
||||
if (cursor_rgb_pixels != NULL)
|
||||
|
|
Loading…
Add table
Reference in a new issue