From f9de3f8216ac689ae78c8d061bfc94508b44acb5 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 12 Jul 2019 13:09:08 +0100 Subject: [PATCH 001/128] Added another bugfix This was causing MSVC debug builds to raise a warning whenever a save was loaded. --- src/Game.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Game.cpp b/src/Game.cpp index 23de4709..fcedce7a 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -559,6 +559,10 @@ int ModeAction(HWND hWnd) ActBullet(); ActCaret(); MoveFrame3(); +#ifdef FIX_BUGS + // ActFlash uses frame_x and frame_y uninitialised + GetFramePosition(&frame_x, &frame_y); +#endif ActFlash(frame_x, frame_y); if (g_GameFlags & 2) From 3ef9b67b1d9ee27137d51494ee63460e89ec45fb Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 15 Jul 2019 11:41:40 +0100 Subject: [PATCH 002/128] Replaced a lot of Draw.cpp with a software renderer Also fixed the SDL_Window not being freed. This commit's a bit of a blob, since I made a bunch of tweaks to Draw.cpp while adding the new renderer. Don't worry though, I'll add the hardware accelerated code back again soon. In fact, I've got an idea on how to make it even faster, while still being able to survive render target losses. Hopefully this software renderer will come in handy for the Wii U port: its SDL2 port's hardware acceleration is broken, and the SDL_Surface API is too slow. --- src/Draw.cpp | 440 +++++++++++++++++++++++++++++++-------------------- src/Draw.h | 12 +- src/Main.cpp | 2 + 3 files changed, 280 insertions(+), 174 deletions(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index 36feedbc..b92cda84 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -18,13 +18,17 @@ struct SURFACE { BOOL in_use; - BOOL needs_updating; - SDL_Surface *surface; - SDL_Texture *texture; + unsigned char *pixels; + unsigned int width; + unsigned int height; + unsigned int pitch; }; SDL_Window *gWindow; -SDL_Renderer *gRenderer; +static SDL_Surface *gWindowSurface; +static SDL_Surface *gSurface; + +static SURFACE framebuffer; RECT grcGame = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; RECT grcFull = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; @@ -64,59 +68,61 @@ BOOL Flip_SystemTask(HWND hWnd) SDL_Delay(1); } - SDL_RenderPresent(gRenderer); + SDL_BlitSurface(gSurface, NULL, gWindowSurface, NULL); + SDL_UpdateWindowSurface(gWindow); + return TRUE; } BOOL StartDirectDraw(int lMagnification, int lColourDepth) { - (void)lColourDepth; + (void)lColourDepth; // There's no way I'm supporting a bunch of different colour depths - // Initialize rendering - SDL_InitSubSystem(SDL_INIT_VIDEO); + switch (lMagnification) + { + case 0: + magnification = 1; + fullscreen = FALSE; + break; + + case 1: + magnification = 2; + fullscreen = FALSE; + break; + + case 2: + magnification = 2; + fullscreen = TRUE; + SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN); + break; + } // Create renderer - gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED); + gWindowSurface = SDL_GetWindowSurface(gWindow); - if (gRenderer != NULL) - { - // Print the name of the renderer SDL2 is using - SDL_RendererInfo info; - SDL_GetRendererInfo(gRenderer, &info); - printf("Renderer: %s\n", info.name); + gSurface = SDL_CreateRGBSurfaceWithFormat(0, WINDOW_WIDTH * magnification, WINDOW_HEIGHT * magnification, 0, SDL_PIXELFORMAT_RGB24); - switch (lMagnification) - { - case 0: - magnification = 1; - fullscreen = FALSE; - break; + if (gSurface == NULL) + return FALSE; - case 1: - magnification = 2; - fullscreen = FALSE; - break; - - case 2: - magnification = 2; - fullscreen = TRUE; - SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN); - break; - } - - } + framebuffer.in_use = TRUE; + framebuffer.pixels = (unsigned char*)gSurface->pixels; + framebuffer.width = WINDOW_WIDTH * magnification; + framebuffer.height = WINDOW_HEIGHT * magnification; + framebuffer.pitch = gSurface->pitch; return TRUE; } void EndDirectDraw() { - // Quit sub-system - SDL_QuitSubSystem(SDL_INIT_VIDEO); - // Release all surfaces for (int i = 0; i < SURFACE_ID_MAX; i++) ReleaseSurface(i); + + framebuffer.in_use = FALSE; + + SDL_FreeSurface(gSurface); } static BOOL IsEnableBitmap(SDL_RWops *fp) @@ -137,8 +143,7 @@ void ReleaseSurface(int s) // Release the surface we want to release if (surf[s].in_use) { - SDL_DestroyTexture(surf[s].texture); - SDL_FreeSurface(surf[s].surface); + free(surf[s].pixels); surf[s].in_use = FALSE; } } @@ -159,34 +164,26 @@ BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no, BOOL bSyst } else { - if (surf[surf_no].in_use == TRUE) + if (surf[surf_no].in_use) { printf("Tried to create drawable surface at occupied slot (%d)\n", surf_no); } else { // Create surface - surf[surf_no].surface = SDL_CreateRGBSurfaceWithFormat(0, bxsize * magnification, bysize * magnification, 0, SDL_PIXELFORMAT_RGB24); - SDL_SetSurfaceBlendMode(surf[surf_no].surface, SDL_BLENDMODE_NONE); + surf[surf_no].pixels = (unsigned char*)malloc((bxsize * magnification) * (bysize * magnification) * 3); + surf[surf_no].width = bxsize * magnification; + surf[surf_no].height = bysize * magnification; + surf[surf_no].pitch = surf[surf_no].width * 3; - if (surf[surf_no].surface == NULL) + if (surf[surf_no].pixels == NULL) { - printf("Failed to create drawable surface %d (SDL_CreateRGBSurfaceWithFormat)\nSDL Error: %s\n", surf_no, SDL_GetError()); + printf("Failed to allocate surface pixel buffer %d\n", surf_no); } else { - surf[surf_no].texture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, bxsize * magnification, bysize * magnification); - - if (surf[surf_no].texture == NULL) - { - printf("Failed to create drawable surface %d (SDL_CreateTexture)\nSDL Error: %s\n", surf_no, SDL_GetError()); - SDL_FreeSurface(surf[surf_no].surface); - } - else - { - surf[surf_no].in_use = TRUE; - success = TRUE; - } + surf[surf_no].in_use = TRUE; + success = TRUE; } } } @@ -194,33 +191,6 @@ BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no, BOOL bSyst return success; } -static void FlushSurface(Surface_Ids surf_no) -{ - unsigned char *raw_pixels; - int pitch; - SDL_LockTexture(surf[surf_no].texture, NULL, (void**)&raw_pixels, &pitch); - - for (int h = 0; h < surf[surf_no].surface->h; ++h) - { - for (int w = 0; w < surf[surf_no].surface->w; ++w) - { - unsigned char *src_pixel = (unsigned char*)surf[surf_no].surface->pixels + (h * surf[surf_no].surface->pitch) + (w * 3); - unsigned char *dst_pixel = (unsigned char*)raw_pixels + (h * pitch) + (w * 4); - - dst_pixel[0] = src_pixel[0]; - dst_pixel[1] = src_pixel[1]; - dst_pixel[2] = src_pixel[2]; - - if (src_pixel[0] || src_pixel[1] || src_pixel[2]) // Colour-key - dst_pixel[3] = 0xFF; - else - dst_pixel[3] = 0; - } - } - - SDL_UnlockTexture(surf[surf_no].texture); -} - static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface) { BOOL success = FALSE; @@ -247,29 +217,34 @@ static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface) { if (create_surface == FALSE || MakeSurface_Generic(surface->w, surface->h, surf_no, FALSE)) { - if (magnification == 1) + + SDL_Surface *converted_surface = SDL_ConvertSurface(surface, gSurface->format, 0); + + if (converted_surface == NULL) { - SDL_Rect dst_rect = {0, 0, surface->w, surface->h}; - SDL_BlitSurface(surface, NULL, surf[surf_no].surface, &dst_rect); - surf[surf_no].needs_updating = TRUE; - printf(" ^ Successfully loaded\n"); - success = TRUE; + printf("Couldn't convert bitmap to surface format (surface id %d)\nSDL Error: %s\n", surf_no, SDL_GetError()); } else { - SDL_Surface *converted_surface = SDL_ConvertSurface(surface, surf[surf_no].surface->format, 0); - - if (converted_surface == NULL) + // IF YOU WANT TO ADD HD SPRITES, THIS IS THE CODE YOU SHOULD EDIT + if (magnification == 1) { - printf("Couldn't convert bitmap to surface format (surface id %d)\nSDL Error: %s\n", surf_no, SDL_GetError()); - } - else - { - // Upscale the bitmap to the game's native resolution (SDL_BlitScaled is buggy, so we have to do it on our own) + // Just copy the pixels the way they are for (int h = 0; h < converted_surface->h; ++h) { const unsigned char *src_row = (unsigned char*)converted_surface->pixels + h * converted_surface->pitch; - unsigned char *dst_row = (unsigned char*)surf[surf_no].surface->pixels + h * surf[surf_no].surface->pitch * magnification; + unsigned char *dst_row = surf[surf_no].pixels + h * surf[surf_no].pitch; + + memcpy(dst_row, src_row, converted_surface->w * 3); + } + } + else + { + // Upscale the bitmap to the game's internal resolution + for (int h = 0; h < converted_surface->h; ++h) + { + const unsigned char *src_row = (unsigned char*)converted_surface->pixels + h * converted_surface->pitch; + unsigned char *dst_row = surf[surf_no].pixels + h * surf[surf_no].pitch * magnification; const unsigned char *src_ptr = src_row; unsigned char *dst_ptr = dst_row; @@ -287,14 +262,14 @@ static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface) } for (int i = 1; i < magnification; ++i) - memcpy(dst_row + i * surf[surf_no].surface->pitch, dst_row, surf[surf_no].surface->w * 3); + memcpy(dst_row + i * surf[surf_no].pitch, dst_row, converted_surface->w * magnification * 3); } - - SDL_FreeSurface(converted_surface); - surf[surf_no].needs_updating = TRUE; - printf(" ^ Successfully loaded\n"); - success = TRUE; } + + SDL_FreeSurface(converted_surface); + //surf[surf_no].needs_updating = TRUE; + printf(" ^ Successfully loaded\n"); + success = TRUE; } } @@ -385,7 +360,7 @@ BOOL ReloadBitmap_Resource(const char *res, Surface_Ids surf_no) { return LoadBitmap_Resource(res, surf_no, FALSE); } - +/* static SDL_Rect RectToSDLRect(RECT *rect) { SDL_Rect SDLRect = {(int)rect->left, (int)rect->top, (int)(rect->right - rect->left), (int)(rect->bottom - rect->top)}; @@ -405,106 +380,246 @@ static SDL_Rect RectToSDLRectScaled(RECT *rect) SDLRect.h *= magnification; return SDLRect; } +*/ -void BackupSurface(Surface_Ids surf_no, RECT *rect) +static void ScaleRect(const RECT *source_rect, RECT *destination_rect) { - // Get renderer size - int w, h; - SDL_GetRendererOutputSize(gRenderer, &w, &h); - - // Get texture of what's currently rendered on screen - SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, SDL_PIXELFORMAT_RGB24); - SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE); - SDL_RenderReadPixels(gRenderer, NULL, SDL_PIXELFORMAT_RGB24, surface->pixels, surface->pitch); - - // Get rects - SDL_Rect frameRect = RectToSDLRectScaled(rect); - - SDL_BlitSurface(surface, &frameRect, surf[surf_no].surface, &frameRect); - surf[surf_no].needs_updating = TRUE; - - // Free surface - SDL_FreeSurface(surface); + destination_rect->left = source_rect->left * magnification; + destination_rect->top = source_rect->top * magnification; + destination_rect->right = source_rect->right * magnification; + destination_rect->bottom = source_rect->bottom * magnification; } -static void DrawBitmap(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no, BOOL transparent) +static void Blit(const SURFACE *source_surface, const RECT *rect, SURFACE *destination_surface, long x, long y, BOOL colour_key) { - if (surf[surf_no].needs_updating) + RECT rect_clamped; + + rect_clamped.left = rect->left; + rect_clamped.top = rect->top; + rect_clamped.right = rect->right; + rect_clamped.bottom = rect->bottom; + + // Clamp the rect and coordinates so we don't write outside the pixel buffer + long overflow; + + overflow = 0 - x; + if (overflow > 0) + { + rect_clamped.left += overflow; + x += overflow; + } + + overflow = 0 - y; + if (overflow > 0) + { + rect_clamped.top += overflow; + y += overflow; + } + + overflow = (x + (rect_clamped.right - rect_clamped.left)) - destination_surface->width; + if (overflow > 0) + { + rect_clamped.right -= overflow; + } + + overflow = (y + (rect_clamped.bottom - rect_clamped.top)) - destination_surface->height; + if (overflow > 0) + { + rect_clamped.bottom -= overflow; + } + + // Do the actual blitting + if (colour_key) + { + for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) + { + unsigned char *source_pointer = &source_surface->pixels[((rect_clamped.top + j) * source_surface->pitch) + (rect_clamped.left * 3)]; + unsigned char *destination_pointer = &destination_surface->pixels[((y + j) * destination_surface->pitch) + (x * 3)]; + + for (long i = 0; i < rect_clamped.right - rect_clamped.left; ++i) + { + if (source_pointer[0] != 0 || source_pointer[1] != 0 || source_pointer[2] != 0) // Assumes the colour key will always be #00000000 (black) + { + destination_pointer[0] = source_pointer[0]; + destination_pointer[1] = source_pointer[1]; + destination_pointer[2] = source_pointer[2]; + } + + source_pointer += 3; + destination_pointer += 3; + } + } + } + else + { + for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) + { + unsigned char *source_pointer = &source_surface->pixels[((rect_clamped.top + j) * source_surface->pitch) + (rect_clamped.left * 3)]; + unsigned char *destination_pointer = &destination_surface->pixels[((y + j) * destination_surface->pitch) + (x * 3)]; + + memcpy(destination_pointer, source_pointer, (rect_clamped.right - rect_clamped.left) * 3); + } + } +} + +static void ColourFill(SURFACE *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +{ + RECT rect_clamped; + + rect_clamped.left = rect->left; + rect_clamped.top = rect->top; + rect_clamped.right = rect->right; + rect_clamped.bottom = rect->bottom; + + // Clamp the rect so it doesn't write outside the pixel buffer + long overflow; + + overflow = 0 - rect_clamped.left; + if (overflow > 0) + { + rect_clamped.left += overflow; + } + + overflow = 0 - rect_clamped.top; + if (overflow > 0) + { + rect_clamped.top += overflow; + } + + overflow = rect_clamped.right - surface->width; + if (overflow > 0) + { + rect_clamped.right -= overflow; + } + + overflow = rect_clamped.bottom - surface->height; + if (overflow > 0) + { + rect_clamped.bottom -= overflow; + } + + for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) + { + unsigned char *source_pointer = &surface->pixels[((rect_clamped.top + j) * surface->pitch) + (rect_clamped.left * 3)]; + + for (long i = 0; i < rect_clamped.right - rect_clamped.left; ++i) + { + *source_pointer++ = red; + *source_pointer++ = green; + *source_pointer++ = blue; + } + } +} + +void BackupSurface(Surface_Ids surf_no, const RECT *rect) +{ + RECT frameRect; + ScaleRect(rect, &frameRect); + + Blit(&framebuffer, &frameRect, &surf[surf_no], frameRect.left, frameRect.top, FALSE); + //surf[surf_no].needs_updating = TRUE; +} + +static void DrawBitmap(const RECT *rcView, int x, int y, const RECT *rect, Surface_Ids surf_no, BOOL transparent) +{ +/* if (surf[surf_no].needs_updating) { FlushSurface(surf_no); surf[surf_no].needs_updating = FALSE; } +*/ + RECT frameRect; - // Get SDL_Rects - SDL_Rect clipRect = RectToSDLRectScaled(rcView); - SDL_Rect frameRect = RectToSDLRectScaled(rect); + frameRect.left = rect->left; + frameRect.top = rect->top; + frameRect.right = rect->right; + frameRect.bottom = rect->bottom; - // Get destination rect - SDL_Rect destRect = {x * magnification, y * magnification, frameRect.w, frameRect.h}; + if (x + (rect->right - rect->left) > rcView->right) + { + frameRect.right -= (x + (rect->right - rect->left)) - rcView->right; + } - // Set cliprect - SDL_RenderSetClipRect(gRenderer, &clipRect); + if (x < rcView->left) + { + frameRect.left += rcView->left - x; + x = rcView->left; + } - SDL_SetTextureBlendMode(surf[surf_no].texture, transparent ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE); + if (y + (rect->bottom - rect->top) > rcView->bottom) + { + frameRect.bottom -= (y + (rect->bottom - rect->top)) - rcView->bottom; + } + + if (y < rcView->top) + { + frameRect.top += rcView->top - y; + y = rcView->top; + } + + frameRect.left *= magnification; + frameRect.top *= magnification; + frameRect.right *= magnification; + frameRect.bottom *= magnification; // Draw to screen - if (SDL_RenderCopy(gRenderer, surf[surf_no].texture, &frameRect, &destRect) < 0) - printf("Failed to draw texture %d\nSDL Error: %s\n", surf_no, SDL_GetError()); - - // Undo cliprect - SDL_RenderSetClipRect(gRenderer, NULL); + Blit(&surf[surf_no], &frameRect, &framebuffer, x * magnification, y * magnification, transparent); } -void PutBitmap3(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no) // Transparency +void PutBitmap3(const RECT *rcView, int x, int y, const RECT *rect, Surface_Ids surf_no) // Transparency { DrawBitmap(rcView, x, y, rect, surf_no, TRUE); } -void PutBitmap4(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no) // No Transparency +void PutBitmap4(const RECT *rcView, int x, int y, const RECT *rect, Surface_Ids surf_no) // No Transparency { DrawBitmap(rcView, x, y, rect, surf_no, FALSE); } -void Surface2Surface(int x, int y, RECT *rect, int to, int from) +void Surface2Surface(int x, int y, const RECT *rect, int to, int from) { // Get rects - SDL_Rect rcSet = {x * magnification, y * magnification, (int)(rect->right - rect->left) * magnification, (int)(rect->bottom - rect->top) * magnification}; - SDL_Rect frameRect = RectToSDLRectScaled(rect); + RECT frameRect; + ScaleRect(rect, &frameRect); - SDL_BlitSurface(surf[from].surface, &frameRect, surf[to].surface, &rcSet); - surf[to].needs_updating = TRUE; + Blit(&surf[from], &frameRect, &surf[to], x * magnification, y * magnification, TRUE); + //surf[to].needs_updating = TRUE; } unsigned long GetCortBoxColor(unsigned long col) { - // This comes in BGR, and goes out BGR + // In vanilla, this called a DirectDraw function to convert it to the 'native' colour type. + // Here, we just return the colour in its original BGR form. return col; } -void CortBox(RECT *rect, unsigned long col) +void CortBox(const RECT *rect, unsigned long col) { // Get rect - SDL_Rect destRect = RectToSDLRectScaled(rect); + RECT destRect; + ScaleRect(rect, &destRect); // Set colour and draw const unsigned char col_red = (unsigned char)(col & 0xFF); const unsigned char col_green = (unsigned char)((col >> 8) & 0xFF); const unsigned char col_blue = (unsigned char)((col >> 16) & 0xFF); - SDL_SetRenderDrawColor(gRenderer, col_red, col_green, col_blue, 0xFF); - SDL_RenderFillRect(gRenderer, &destRect); + + ColourFill(&framebuffer, &destRect, col_red, col_green, col_blue); } -void CortBox2(RECT *rect, unsigned long col, Surface_Ids surf_no) +void CortBox2(const RECT *rect, unsigned long col, Surface_Ids surf_no) { // Get rect - SDL_Rect destRect = RectToSDLRectScaled(rect); + RECT destRect; + ScaleRect(rect, &destRect); // Set colour and draw const unsigned char col_red = (unsigned char)(col & 0xFF); const unsigned char col_green = (unsigned char)((col >> 8) & 0xFF); const unsigned char col_blue = (unsigned char)((col >> 16) & 0xFF); - SDL_FillRect(surf[surf_no].surface, &destRect, SDL_MapRGB(surf[surf_no].surface->format, col_red, col_green, col_blue)); - surf[surf_no].needs_updating = TRUE; + + ColourFill(&surf[surf_no], &destRect, col_red, col_green, col_blue); + //surf[surf_no].needs_updating = TRUE; } #ifdef WINDOWS @@ -608,24 +723,13 @@ void InitTextObject(const char *font_name) void PutText(int x, int y, const char *text, unsigned long color) { - int surface_width, surface_height; - SDL_GetRendererOutputSize(gRenderer, &surface_width, &surface_height); - - SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, surface_width, surface_height, 0, SDL_PIXELFORMAT_RGB24); - SDL_RenderReadPixels(gRenderer, NULL, SDL_PIXELFORMAT_RGB24, surface->pixels, surface->pitch); - - DrawText(gFont, (unsigned char*)surface->pixels, surface->pitch, surface->w, surface->h, x * magnification, y * magnification, color, text, strlen(text)); - - SDL_Texture *screen_texture = SDL_CreateTextureFromSurface(gRenderer, surface); - SDL_FreeSurface(surface); - SDL_RenderCopy(gRenderer, screen_texture, NULL, NULL); - SDL_DestroyTexture(screen_texture); + DrawText(gFont, framebuffer.pixels, framebuffer.pitch, framebuffer.width, framebuffer.height, x * magnification, y * magnification, color, text, strlen(text)); } void PutText2(int x, int y, const char *text, unsigned long color, Surface_Ids surf_no) { - DrawText(gFont, (unsigned char*)surf[surf_no].surface->pixels, surf[surf_no].surface->pitch, surf[surf_no].surface->w, surf[surf_no].surface->h, x * magnification, y * magnification, color, text, strlen(text)); - surf[surf_no].needs_updating = TRUE; + DrawText(gFont, surf[surf_no].pixels, surf[surf_no].pitch, surf[surf_no].width, surf[surf_no].height, x * magnification, y * magnification, color, text, strlen(text)); + //surf[surf_no].needs_updating = TRUE; } void EndTextObject() diff --git a/src/Draw.h b/src/Draw.h index cfef72b7..d50bef34 100644 --- a/src/Draw.h +++ b/src/Draw.h @@ -61,13 +61,13 @@ BOOL MakeSurface_Resource(const char *res, Surface_Ids surf_no); BOOL ReloadBitmap_File(const char *name, Surface_Ids surf_no); BOOL ReloadBitmap_Resource(const char *res, Surface_Ids surf_no); BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no, BOOL bSystem); -void BackupSurface(Surface_Ids surf_no, RECT *rect); -void PutBitmap3(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no); -void PutBitmap4(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no); -void Surface2Surface(int x, int y, RECT *rect, int to, int from); +void BackupSurface(Surface_Ids surf_no, const RECT *rect); +void PutBitmap3(const RECT *rcView, int x, int y, const RECT *rect, Surface_Ids surf_no); +void PutBitmap4(const RECT *rcView, int x, int y, const RECT *rect, Surface_Ids surf_no); +void Surface2Surface(int x, int y, const RECT *rect, int to, int from); unsigned long GetCortBoxColor(unsigned long col); -void CortBox(RECT *rect, unsigned long col); -void CortBox2(RECT *rect, unsigned long col, Surface_Ids surf_no); +void CortBox(const RECT *rect, unsigned long col); +void CortBox2(const RECT *rect, unsigned long col, Surface_Ids surf_no); void InitTextObject(const char *font_name); void PutText(int x, int y, const char *text, unsigned long color); void PutText2(int x, int y, const char *text, unsigned long color, Surface_Ids surf_no); diff --git a/src/Main.cpp b/src/Main.cpp index 34249f4b..ea6fc2fc 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -373,6 +373,8 @@ int main(int argc, char *argv[]) EndTextObject(); EndDirectDraw(); } + + SDL_DestroyWindow(gWindow); } } else From 21cf78b86d1025081e59d3edffc59a8ef5b18148 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 15 Jul 2019 13:41:19 +0100 Subject: [PATCH 003/128] Split Draw.cpp into common code and backend code Should be easy to add the new hardware renderer now --- CMakeLists.txt | 2 + src/Backends/Rendering.h | 23 ++++ src/Backends/SDLSoftware.cpp | 239 +++++++++++++++++++++++++++++++++++ src/Draw.cpp | 196 +++++----------------------- 4 files changed, 293 insertions(+), 167 deletions(-) create mode 100644 src/Backends/Rendering.h create mode 100644 src/Backends/SDLSoftware.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d0fcd886..4ef63cbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,6 +155,8 @@ add_executable(CSE2 src/ValueView.cpp src/ValueView.h src/WindowsWrapper.h + src/Backends/SDLSoftware.cpp + src/Backends/Rendering.h ) set(RESOURCES diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h new file mode 100644 index 00000000..60ff001f --- /dev/null +++ b/src/Backends/Rendering.h @@ -0,0 +1,23 @@ +#pragma once + +#include "SDL.h" + +#include "../WindowsWrapper.h" + +#include "../Font.h" + +struct Backend_Surface; + +BOOL Backend_Init(SDL_Window *window); +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); +void Backend_Blit(const Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key); +void Backend_BlitToScreen(const 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); +void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue); +void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect); +void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour); +void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour); diff --git a/src/Backends/SDLSoftware.cpp b/src/Backends/SDLSoftware.cpp new file mode 100644 index 00000000..1764334d --- /dev/null +++ b/src/Backends/SDLSoftware.cpp @@ -0,0 +1,239 @@ +#include "Rendering.h" + +#include +#include + +#include "SDL.h" + +#include "../WindowsWrapper.h" + +#include "../Font.h" + +struct Backend_Surface +{ + unsigned char *pixels; + unsigned int width; + unsigned int height; + unsigned int pitch; +}; + +static SDL_Window *window; +static SDL_Surface *window_surface; +static SDL_Surface *screen_surface; + +static Backend_Surface framebuffer; + +BOOL Backend_Init(SDL_Window *p_window) +{ + window = p_window; + + window_surface = SDL_GetWindowSurface(window); + + screen_surface = SDL_CreateRGBSurfaceWithFormat(0, window_surface->w, window_surface->h, 0, SDL_PIXELFORMAT_RGB24); + + if (screen_surface == NULL) + return FALSE; + + framebuffer.pixels = (unsigned char*)screen_surface->pixels; + framebuffer.width = screen_surface->w; + framebuffer.height = screen_surface->h; + framebuffer.pitch = screen_surface->pitch; + + return TRUE; +} + +void Backend_Deinit(void) +{ + SDL_FreeSurface(screen_surface); +} + +void Backend_DrawScreen(void) +{ + SDL_BlitSurface(screen_surface, NULL, window_surface, NULL); + SDL_UpdateWindowSurface(window); +} + +Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) +{ + Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); + + if (surface == NULL) + return NULL; + + surface->pixels = (unsigned char*)malloc(width * height * 3); + + if (surface->pixels == NULL) + { + free(surface); + return NULL; + } + + surface->width = width; + surface->height = height; + surface->pitch = width * 3; + + return surface; +} + +void Backend_FreeSurface(Backend_Surface *surface) +{ + free(surface->pixels); +} + +void Backend_LoadPixels(Backend_Surface *surface, const unsigned char *pixels, unsigned int width, unsigned int height, unsigned int pitch) +{ + for (unsigned int h = 0; h < height; ++h) + { + const unsigned char *src_row = &pixels[h * pitch]; + unsigned char *dst_row = &surface->pixels[h * surface->pitch]; + + memcpy(dst_row, src_row, width * 3); + } +} + +void Backend_Blit(const Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) +{ + RECT rect_clamped; + + rect_clamped.left = rect->left; + rect_clamped.top = rect->top; + rect_clamped.right = rect->right; + rect_clamped.bottom = rect->bottom; + + // Clamp the rect and coordinates so we don't write outside the pixel buffer + long overflow; + + overflow = 0 - x; + if (overflow > 0) + { + rect_clamped.left += overflow; + x += overflow; + } + + overflow = 0 - y; + if (overflow > 0) + { + rect_clamped.top += overflow; + y += overflow; + } + + overflow = (x + (rect_clamped.right - rect_clamped.left)) - destination_surface->width; + if (overflow > 0) + { + rect_clamped.right -= overflow; + } + + overflow = (y + (rect_clamped.bottom - rect_clamped.top)) - destination_surface->height; + if (overflow > 0) + { + rect_clamped.bottom -= overflow; + } + + // Do the actual blitting + if (colour_key) + { + for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) + { + unsigned char *source_pointer = &source_surface->pixels[((rect_clamped.top + j) * source_surface->pitch) + (rect_clamped.left * 3)]; + unsigned char *destination_pointer = &destination_surface->pixels[((y + j) * destination_surface->pitch) + (x * 3)]; + + for (long i = 0; i < rect_clamped.right - rect_clamped.left; ++i) + { + if (source_pointer[0] != 0 || source_pointer[1] != 0 || source_pointer[2] != 0) // Assumes the colour key will always be #00000000 (black) + { + destination_pointer[0] = source_pointer[0]; + destination_pointer[1] = source_pointer[1]; + destination_pointer[2] = source_pointer[2]; + } + + source_pointer += 3; + destination_pointer += 3; + } + } + } + else + { + for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) + { + unsigned char *source_pointer = &source_surface->pixels[((rect_clamped.top + j) * source_surface->pitch) + (rect_clamped.left * 3)]; + unsigned char *destination_pointer = &destination_surface->pixels[((y + j) * destination_surface->pitch) + (x * 3)]; + + memcpy(destination_pointer, source_pointer, (rect_clamped.right - rect_clamped.left) * 3); + } + } +} + +void Backend_BlitToScreen(const Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) +{ + Backend_Blit(source_surface, rect, &framebuffer, x, y, colour_key); +} + +void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +{ + RECT rect_clamped; + + rect_clamped.left = rect->left; + rect_clamped.top = rect->top; + rect_clamped.right = rect->right; + rect_clamped.bottom = rect->bottom; + + // Clamp the rect so it doesn't write outside the pixel buffer + long overflow; + + overflow = 0 - rect_clamped.left; + if (overflow > 0) + { + rect_clamped.left += overflow; + } + + overflow = 0 - rect_clamped.top; + if (overflow > 0) + { + rect_clamped.top += overflow; + } + + overflow = rect_clamped.right - surface->width; + if (overflow > 0) + { + rect_clamped.right -= overflow; + } + + overflow = rect_clamped.bottom - surface->height; + if (overflow > 0) + { + rect_clamped.bottom -= overflow; + } + + for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) + { + unsigned char *source_pointer = &surface->pixels[((rect_clamped.top + j) * surface->pitch) + (rect_clamped.left * 3)]; + + for (long i = 0; i < rect_clamped.right - rect_clamped.left; ++i) + { + *source_pointer++ = red; + *source_pointer++ = green; + *source_pointer++ = blue; + } + } +} + +void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +{ + Backend_ColourFill(&framebuffer, rect, red, green, blue); +} + +void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) +{ + Backend_Blit(&framebuffer, rect, surface, rect->left, rect->top, FALSE); +} + +void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour) +{ + DrawText(font, surface->pixels, surface->pitch, surface->width, surface->height, x, y, colour, text, strlen(text)); + //surf[surf_no].needs_updating = TRUE; +} + +void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour) +{ + Backend_DrawText(&framebuffer, font, x, y, text, colour); +} diff --git a/src/Draw.cpp b/src/Draw.cpp index b92cda84..0b12fb80 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -14,21 +14,17 @@ #include "Font.h" #include "Resource.h" #include "Tags.h" +#include "Backends/Rendering.h" struct SURFACE { BOOL in_use; - unsigned char *pixels; - unsigned int width; - unsigned int height; - unsigned int pitch; + Backend_Surface *backend; }; SDL_Window *gWindow; -static SDL_Surface *gWindowSurface; -static SDL_Surface *gSurface; -static SURFACE framebuffer; +static SDL_PixelFormat *rgb24_pixel_format; // Needed because SDL2 is stupid RECT grcGame = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; RECT grcFull = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; @@ -68,8 +64,7 @@ BOOL Flip_SystemTask(HWND hWnd) SDL_Delay(1); } - SDL_BlitSurface(gSurface, NULL, gWindowSurface, NULL); - SDL_UpdateWindowSurface(gWindow); + Backend_DrawScreen(); return TRUE; } @@ -98,31 +93,23 @@ BOOL StartDirectDraw(int lMagnification, int lColourDepth) } // Create renderer - gWindowSurface = SDL_GetWindowSurface(gWindow); - - gSurface = SDL_CreateRGBSurfaceWithFormat(0, WINDOW_WIDTH * magnification, WINDOW_HEIGHT * magnification, 0, SDL_PIXELFORMAT_RGB24); - - if (gSurface == NULL) + if (!Backend_Init(gWindow)) return FALSE; - framebuffer.in_use = TRUE; - framebuffer.pixels = (unsigned char*)gSurface->pixels; - framebuffer.width = WINDOW_WIDTH * magnification; - framebuffer.height = WINDOW_HEIGHT * magnification; - framebuffer.pitch = gSurface->pitch; + rgb24_pixel_format = SDL_AllocFormat(SDL_PIXELFORMAT_RGB24); return TRUE; } void EndDirectDraw() { + SDL_FreeFormat(rgb24_pixel_format); + // Release all surfaces for (int i = 0; i < SURFACE_ID_MAX; i++) ReleaseSurface(i); - framebuffer.in_use = FALSE; - - SDL_FreeSurface(gSurface); + Backend_Deinit(); } static BOOL IsEnableBitmap(SDL_RWops *fp) @@ -143,7 +130,7 @@ void ReleaseSurface(int s) // Release the surface we want to release if (surf[s].in_use) { - free(surf[s].pixels); + Backend_FreeSurface(surf[s].backend); surf[s].in_use = FALSE; } } @@ -171,14 +158,11 @@ BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no, BOOL bSyst else { // Create surface - surf[surf_no].pixels = (unsigned char*)malloc((bxsize * magnification) * (bysize * magnification) * 3); - surf[surf_no].width = bxsize * magnification; - surf[surf_no].height = bysize * magnification; - surf[surf_no].pitch = surf[surf_no].width * 3; + surf[surf_no].backend = Backend_CreateSurface(bxsize * magnification, bysize * magnification); - if (surf[surf_no].pixels == NULL) + if (surf[surf_no].backend == NULL) { - printf("Failed to allocate surface pixel buffer %d\n", surf_no); + printf("Failed to create backend surface %d\n", surf_no); } else { @@ -218,7 +202,7 @@ static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface) if (create_surface == FALSE || MakeSurface_Generic(surface->w, surface->h, surf_no, FALSE)) { - SDL_Surface *converted_surface = SDL_ConvertSurface(surface, gSurface->format, 0); + SDL_Surface *converted_surface = SDL_ConvertSurface(surface, rgb24_pixel_format, 0); if (converted_surface == NULL) { @@ -230,21 +214,17 @@ static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface) if (magnification == 1) { // Just copy the pixels the way they are - for (int h = 0; h < converted_surface->h; ++h) - { - const unsigned char *src_row = (unsigned char*)converted_surface->pixels + h * converted_surface->pitch; - unsigned char *dst_row = surf[surf_no].pixels + h * surf[surf_no].pitch; - - memcpy(dst_row, src_row, converted_surface->w * 3); - } + Backend_LoadPixels(surf[surf_no].backend, (unsigned char*)converted_surface->pixels, converted_surface->w, converted_surface->h, converted_surface->pitch); } 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) { const unsigned char *src_row = (unsigned char*)converted_surface->pixels + h * converted_surface->pitch; - unsigned char *dst_row = surf[surf_no].pixels + h * surf[surf_no].pitch * magnification; + unsigned char *dst_row = pixels + h * (converted_surface->w * magnification * 3) * magnification; const unsigned char *src_ptr = src_row; unsigned char *dst_ptr = dst_row; @@ -262,8 +242,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 * surf[surf_no].pitch, dst_row, converted_surface->w * magnification * 3); + memcpy(dst_row + i * converted_surface->w * magnification * 3, 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); } SDL_FreeSurface(converted_surface); @@ -390,133 +373,12 @@ static void ScaleRect(const RECT *source_rect, RECT *destination_rect) destination_rect->bottom = source_rect->bottom * magnification; } -static void Blit(const SURFACE *source_surface, const RECT *rect, SURFACE *destination_surface, long x, long y, BOOL colour_key) -{ - RECT rect_clamped; - - rect_clamped.left = rect->left; - rect_clamped.top = rect->top; - rect_clamped.right = rect->right; - rect_clamped.bottom = rect->bottom; - - // Clamp the rect and coordinates so we don't write outside the pixel buffer - long overflow; - - overflow = 0 - x; - if (overflow > 0) - { - rect_clamped.left += overflow; - x += overflow; - } - - overflow = 0 - y; - if (overflow > 0) - { - rect_clamped.top += overflow; - y += overflow; - } - - overflow = (x + (rect_clamped.right - rect_clamped.left)) - destination_surface->width; - if (overflow > 0) - { - rect_clamped.right -= overflow; - } - - overflow = (y + (rect_clamped.bottom - rect_clamped.top)) - destination_surface->height; - if (overflow > 0) - { - rect_clamped.bottom -= overflow; - } - - // Do the actual blitting - if (colour_key) - { - for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) - { - unsigned char *source_pointer = &source_surface->pixels[((rect_clamped.top + j) * source_surface->pitch) + (rect_clamped.left * 3)]; - unsigned char *destination_pointer = &destination_surface->pixels[((y + j) * destination_surface->pitch) + (x * 3)]; - - for (long i = 0; i < rect_clamped.right - rect_clamped.left; ++i) - { - if (source_pointer[0] != 0 || source_pointer[1] != 0 || source_pointer[2] != 0) // Assumes the colour key will always be #00000000 (black) - { - destination_pointer[0] = source_pointer[0]; - destination_pointer[1] = source_pointer[1]; - destination_pointer[2] = source_pointer[2]; - } - - source_pointer += 3; - destination_pointer += 3; - } - } - } - else - { - for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) - { - unsigned char *source_pointer = &source_surface->pixels[((rect_clamped.top + j) * source_surface->pitch) + (rect_clamped.left * 3)]; - unsigned char *destination_pointer = &destination_surface->pixels[((y + j) * destination_surface->pitch) + (x * 3)]; - - memcpy(destination_pointer, source_pointer, (rect_clamped.right - rect_clamped.left) * 3); - } - } -} - -static void ColourFill(SURFACE *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) -{ - RECT rect_clamped; - - rect_clamped.left = rect->left; - rect_clamped.top = rect->top; - rect_clamped.right = rect->right; - rect_clamped.bottom = rect->bottom; - - // Clamp the rect so it doesn't write outside the pixel buffer - long overflow; - - overflow = 0 - rect_clamped.left; - if (overflow > 0) - { - rect_clamped.left += overflow; - } - - overflow = 0 - rect_clamped.top; - if (overflow > 0) - { - rect_clamped.top += overflow; - } - - overflow = rect_clamped.right - surface->width; - if (overflow > 0) - { - rect_clamped.right -= overflow; - } - - overflow = rect_clamped.bottom - surface->height; - if (overflow > 0) - { - rect_clamped.bottom -= overflow; - } - - for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) - { - unsigned char *source_pointer = &surface->pixels[((rect_clamped.top + j) * surface->pitch) + (rect_clamped.left * 3)]; - - for (long i = 0; i < rect_clamped.right - rect_clamped.left; ++i) - { - *source_pointer++ = red; - *source_pointer++ = green; - *source_pointer++ = blue; - } - } -} - void BackupSurface(Surface_Ids surf_no, const RECT *rect) { RECT frameRect; ScaleRect(rect, &frameRect); - Blit(&framebuffer, &frameRect, &surf[surf_no], frameRect.left, frameRect.top, FALSE); + Backend_ScreenToSurface(surf[surf_no].backend, &frameRect); //surf[surf_no].needs_updating = TRUE; } @@ -563,7 +425,7 @@ static void DrawBitmap(const RECT *rcView, int x, int y, const RECT *rect, Surfa frameRect.bottom *= magnification; // Draw to screen - Blit(&surf[surf_no], &frameRect, &framebuffer, x * magnification, y * magnification, transparent); + Backend_BlitToScreen(surf[surf_no].backend, &frameRect, x * magnification, y * magnification, transparent); } void PutBitmap3(const RECT *rcView, int x, int y, const RECT *rect, Surface_Ids surf_no) // Transparency @@ -582,7 +444,7 @@ void Surface2Surface(int x, int y, const RECT *rect, int to, int from) RECT frameRect; ScaleRect(rect, &frameRect); - Blit(&surf[from], &frameRect, &surf[to], x * magnification, y * magnification, TRUE); + Backend_Blit(surf[from].backend, &frameRect, surf[to].backend, x * magnification, y * magnification, TRUE); //surf[to].needs_updating = TRUE; } @@ -604,7 +466,7 @@ void CortBox(const RECT *rect, unsigned long col) const unsigned char col_green = (unsigned char)((col >> 8) & 0xFF); const unsigned char col_blue = (unsigned char)((col >> 16) & 0xFF); - ColourFill(&framebuffer, &destRect, col_red, col_green, col_blue); + Backend_ColourFillToScreen(&destRect, col_red, col_green, col_blue); } void CortBox2(const RECT *rect, unsigned long col, Surface_Ids surf_no) @@ -618,7 +480,7 @@ void CortBox2(const RECT *rect, unsigned long col, Surface_Ids surf_no) const unsigned char col_green = (unsigned char)((col >> 8) & 0xFF); const unsigned char col_blue = (unsigned char)((col >> 16) & 0xFF); - ColourFill(&surf[surf_no], &destRect, col_red, col_green, col_blue); + Backend_ColourFill(surf[surf_no].backend, &destRect, col_red, col_green, col_blue); //surf[surf_no].needs_updating = TRUE; } @@ -723,12 +585,12 @@ void InitTextObject(const char *font_name) void PutText(int x, int y, const char *text, unsigned long color) { - DrawText(gFont, framebuffer.pixels, framebuffer.pitch, framebuffer.width, framebuffer.height, x * magnification, y * magnification, color, text, strlen(text)); + Backend_DrawTextToScreen(gFont, x * magnification, y * magnification, text, color); } void PutText2(int x, int y, const char *text, unsigned long color, Surface_Ids surf_no) { - DrawText(gFont, surf[surf_no].pixels, surf[surf_no].pitch, surf[surf_no].width, surf[surf_no].height, x * magnification, y * magnification, color, text, strlen(text)); + Backend_DrawText(surf[surf_no].backend, gFont, x * magnification, y * magnification, text, color); //surf[surf_no].needs_updating = TRUE; } From 15bfd00d25610e34b001acc89a7d222f3b78f282 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 15 Jul 2019 16:47:10 +0100 Subject: [PATCH 004/128] Added hardware-accelerated rendering backend Still need to add the code for surviving render target losses --- CMakeLists.txt | 8 +- src/Backends/Rendering.h | 4 +- src/Backends/SDLSoftware.cpp | 5 +- src/Backends/SDLTexture.cpp | 276 +++++++++++++++++++++++++++++++++++ src/Draw.cpp | 31 ---- 5 files changed, 288 insertions(+), 36 deletions(-) create mode 100644 src/Backends/SDLTexture.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ef63cbd..5efe064e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ option(JAPANESE "Enable the Japanese-language build" OFF) option(FIX_BUGS "Fix certain bugs (see src/Bug Fixes.txt)" OFF) option(NONPORTABLE "Enable bits of code that aren't portable, but are what the original game used" OFF) option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF) +set(RENDERER "Texture" CACHE STRING "Which renderer the game should use: 'Texture' for SDL2's hardware-accelerated Texture API, and 'Software' for a handwritten software renderer") project(CSE2 LANGUAGES C CXX) @@ -155,7 +156,6 @@ add_executable(CSE2 src/ValueView.cpp src/ValueView.h src/WindowsWrapper.h - src/Backends/SDLSoftware.cpp src/Backends/Rendering.h ) @@ -246,6 +246,12 @@ if(NONPORTABLE) target_compile_definitions(CSE2 PRIVATE NONPORTABLE) endif() +if(RENDERER MATCHES "Texture") + target_sources(CSE2 PRIVATE "src/Backends/SDLTexture.cpp") +elseif(RENDERER MATCHES "Software") + target_sources(CSE2 PRIVATE "src/Backends/SDLSoftware.cpp") +endif() + # Make some tweaks if we're targetting Windows if(WIN32) target_sources(CSE2 PRIVATE "${ASSETS_DIRECTORY}/resources/ICON/ICON.rc") diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index 60ff001f..9416c958 100644 --- a/src/Backends/Rendering.h +++ b/src/Backends/Rendering.h @@ -14,8 +14,8 @@ 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); -void Backend_Blit(const Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key); -void Backend_BlitToScreen(const Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key); +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); void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue); void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect); diff --git a/src/Backends/SDLSoftware.cpp b/src/Backends/SDLSoftware.cpp index 1764334d..b9ed8b33 100644 --- a/src/Backends/SDLSoftware.cpp +++ b/src/Backends/SDLSoftware.cpp @@ -78,6 +78,7 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) void Backend_FreeSurface(Backend_Surface *surface) { free(surface->pixels); + free(surface); } void Backend_LoadPixels(Backend_Surface *surface, const unsigned char *pixels, unsigned int width, unsigned int height, unsigned int pitch) @@ -91,7 +92,7 @@ void Backend_LoadPixels(Backend_Surface *surface, const unsigned char *pixels, u } } -void Backend_Blit(const Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) +void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) { RECT rect_clamped; @@ -163,7 +164,7 @@ void Backend_Blit(const Backend_Surface *source_surface, const RECT *rect, Backe } } -void Backend_BlitToScreen(const Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) +void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) { Backend_Blit(source_surface, rect, &framebuffer, x, y, colour_key); } diff --git a/src/Backends/SDLTexture.cpp b/src/Backends/SDLTexture.cpp new file mode 100644 index 00000000..f4475397 --- /dev/null +++ b/src/Backends/SDLTexture.cpp @@ -0,0 +1,276 @@ +#include "Rendering.h" + +#include +#include + +#include "SDL.h" + +#include "../WindowsWrapper.h" + +#include "../Font.h" + +struct Backend_Surface +{ + BOOL needs_syncing; + SDL_Surface *sdl_surface; + SDL_Texture *texture; +}; + +static SDL_Renderer *renderer; +static SDL_Texture *screen_texture; + +static void FlushSurface(Backend_Surface *surface) +{ + unsigned char *buffer = (unsigned char*)malloc(surface->sdl_surface->w * surface->sdl_surface->h * 4); + unsigned char *buffer_pointer = buffer; + + // Convert the SDL_Surface's colour-keyed pixels to RGBA32 + for (int h = 0; h < surface->sdl_surface->h; ++h) + { + unsigned char *src_pixel = (unsigned char*)surface->sdl_surface->pixels + (h * surface->sdl_surface->pitch); + + for (int w = 0; w < surface->sdl_surface->w; ++w) + { + *buffer_pointer++ = src_pixel[0]; + *buffer_pointer++ = src_pixel[1]; + *buffer_pointer++ = src_pixel[2]; + + if (src_pixel[0] != 0 || src_pixel[1] != 0 || src_pixel[2] != 0) // Assumes the colour key will always be #00000000 (black) + *buffer_pointer++ = 0xFF; + else + *buffer_pointer++ = 0; + + src_pixel += 3; + } + } + + SDL_UpdateTexture(surface->texture, NULL, buffer, surface->sdl_surface->w * 4); + + free(buffer); +} + +static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect) +{ + sdl_rect->x = (int)rect->left; + sdl_rect->y = (int)rect->top; + sdl_rect->w = (int)(rect->right - rect->left); + sdl_rect->h = (int)(rect->bottom - rect->top); + + if (sdl_rect->w < 0) + sdl_rect->w = 0; + + if (sdl_rect->h < 0) + sdl_rect->h = 0; +} + +BOOL Backend_Init(SDL_Window *window) +{ + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); + + if (renderer == NULL) + return FALSE; + + int width, height; + SDL_GetRendererOutputSize(renderer, &width, &height); + screen_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, width, height); + + SDL_SetRenderTarget(renderer, screen_texture); + + return TRUE; +} + +void Backend_Deinit(void) +{ + SDL_DestroyRenderer(renderer); +} + +void Backend_DrawScreen(void) +{ + SDL_SetRenderTarget(renderer, NULL); + SDL_RenderCopy(renderer, screen_texture, NULL, NULL); + SDL_SetRenderTarget(renderer, screen_texture); + SDL_RenderPresent(renderer); +} + +Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) +{ + Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); + + if (surface == NULL) + return NULL; + + surface->sdl_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, SDL_PIXELFORMAT_RGB24); + + if (surface->sdl_surface == NULL) + { + free(surface); + return NULL; + } + + surface->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, width, height); + + if (surface->texture == NULL) + { + SDL_FreeSurface(surface->sdl_surface); + free(surface); + return NULL; + } + + SDL_SetColorKey(surface->sdl_surface, SDL_TRUE, SDL_MapRGB(surface->sdl_surface->format, 0, 0, 0)); + + surface->needs_syncing = FALSE; + + return surface; +} + +void Backend_FreeSurface(Backend_Surface *surface) +{ + SDL_FreeSurface(surface->sdl_surface); + free(surface); +} + +void Backend_LoadPixels(Backend_Surface *surface, const unsigned char *pixels, unsigned int width, unsigned int height, unsigned int pitch) +{ + for (unsigned int h = 0; h < height; ++h) + { + const unsigned char *src_row = &pixels[h * pitch]; + unsigned char *dst_row = (unsigned char*)surface->sdl_surface->pixels + h * surface->sdl_surface->pitch; + + memcpy(dst_row, src_row, width * 3); + } + + surface->needs_syncing = TRUE; +} + +void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) +{ + if (source_surface->needs_syncing) + { + FlushSurface(source_surface); + source_surface->needs_syncing = FALSE; + } + + SDL_Rect source_rect; + RectToSDLRect(rect, &source_rect); + + SDL_Rect destination_rect = {x, y, source_rect.w, source_rect.h}; + + // Blit the surface + SDL_SetSurfaceBlendMode(source_surface->sdl_surface, colour_key ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE); + SDL_BlitSurface(source_surface->sdl_surface, &source_rect, destination_surface->sdl_surface, &destination_rect); + + // Now blit the texture + SDL_SetTextureBlendMode(source_surface->texture, colour_key ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE); + SDL_SetRenderTarget(renderer, destination_surface->texture); + SDL_RenderCopy(renderer, source_surface->texture, &source_rect, &destination_rect); + SDL_SetRenderTarget(renderer, screen_texture); +} + +void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) +{ + if (source_surface->needs_syncing) + { + FlushSurface(source_surface); + source_surface->needs_syncing = FALSE; + } + + SDL_Rect source_rect; + RectToSDLRect(rect, &source_rect); + + SDL_Rect destination_rect = {x, y, source_rect.w, source_rect.h}; + + // Blit the texture + SDL_SetTextureBlendMode(source_surface->texture, colour_key ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE); + SDL_RenderCopy(renderer, source_surface->texture, &source_rect, &destination_rect); +} + +void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +{ + SDL_Rect sdl_rect; + RectToSDLRect(rect, &sdl_rect); + + // Blit the surface + SDL_FillRect(surface->sdl_surface, &sdl_rect, SDL_MapRGB(surface->sdl_surface->format, red, green, blue)); + + // Check colour-key + if (red == 0 && green == 0 && blue == 0) + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); + else + SDL_SetRenderDrawColor(renderer, red, green, blue, 0xFF); + + // Draw colour + SDL_SetRenderTarget(renderer, surface->texture); + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); + SDL_RenderFillRect(renderer, &sdl_rect); + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); + SDL_SetRenderTarget(renderer, screen_texture); +} + +void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +{ + SDL_Rect sdl_rect; + RectToSDLRect(rect, &sdl_rect); + + // Draw colour + SDL_SetRenderDrawColor(renderer, red, green, blue, 0xFF); + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); + SDL_RenderFillRect(renderer, &sdl_rect); + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); +} + +void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) +{ + SDL_Rect sdl_rect; + RectToSDLRect(rect, &sdl_rect); + + + // + // Copy screen to surface + // + + // Get renderer size + int w, h; + SDL_GetRendererOutputSize(renderer, &w, &h); + + // Get surface of what's currently rendered on screen + SDL_Surface *screen_surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, SDL_PIXELFORMAT_RGB24); + SDL_RenderReadPixels(renderer, NULL, SDL_PIXELFORMAT_RGB24, screen_surface->pixels, screen_surface->pitch); + + // Copy to specified surface + SDL_BlitSurface(screen_surface, &sdl_rect, surface->sdl_surface, &sdl_rect); + + // Cleanup + SDL_FreeSurface(screen_surface); + + + // + // Copy screen to texture + // + + SDL_SetRenderTarget(renderer, surface->texture); + SDL_RenderCopy(renderer, screen_texture, &sdl_rect, &sdl_rect); + SDL_SetRenderTarget(renderer, screen_texture); +} + +void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour) +{ + DrawText(font, (unsigned char*)surface->sdl_surface->pixels, surface->sdl_surface->pitch, surface->sdl_surface->w, surface->sdl_surface->h, x, y, colour, text, strlen(text)); + surface->needs_syncing = TRUE; +} + +void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour) +{ + // Painfully slow. Really need to add hardware-accelerated font rendering. + int surface_width, surface_height; + SDL_GetRendererOutputSize(renderer, &surface_width, &surface_height); + + SDL_Surface *screen_surface = SDL_CreateRGBSurfaceWithFormat(0, surface_width, surface_height, 0, SDL_PIXELFORMAT_RGB24); + SDL_RenderReadPixels(renderer, NULL, SDL_PIXELFORMAT_RGB24, screen_surface->pixels, screen_surface->pitch); + + DrawText(font, (unsigned char*)screen_surface->pixels, screen_surface->pitch, screen_surface->w, screen_surface->h, x, y, colour, text, strlen(text)); + + SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, screen_surface); + SDL_FreeSurface(screen_surface); + SDL_RenderCopy(renderer, texture, NULL, NULL); + SDL_DestroyTexture(texture); +} diff --git a/src/Draw.cpp b/src/Draw.cpp index 0b12fb80..8d81b01e 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -343,27 +343,6 @@ BOOL ReloadBitmap_Resource(const char *res, Surface_Ids surf_no) { return LoadBitmap_Resource(res, surf_no, FALSE); } -/* -static SDL_Rect RectToSDLRect(RECT *rect) -{ - SDL_Rect SDLRect = {(int)rect->left, (int)rect->top, (int)(rect->right - rect->left), (int)(rect->bottom - rect->top)}; - if (SDLRect.w < 0) - SDLRect.w = 0; - if (SDLRect.h < 0) - SDLRect.h = 0; - return SDLRect; -} - -static SDL_Rect RectToSDLRectScaled(RECT *rect) -{ - SDL_Rect SDLRect = RectToSDLRect(rect); - SDLRect.x *= magnification; - SDLRect.y *= magnification; - SDLRect.w *= magnification; - SDLRect.h *= magnification; - return SDLRect; -} -*/ static void ScaleRect(const RECT *source_rect, RECT *destination_rect) { @@ -379,17 +358,10 @@ void BackupSurface(Surface_Ids surf_no, const RECT *rect) ScaleRect(rect, &frameRect); Backend_ScreenToSurface(surf[surf_no].backend, &frameRect); - //surf[surf_no].needs_updating = TRUE; } static void DrawBitmap(const RECT *rcView, int x, int y, const RECT *rect, Surface_Ids surf_no, BOOL transparent) { -/* if (surf[surf_no].needs_updating) - { - FlushSurface(surf_no); - surf[surf_no].needs_updating = FALSE; - } -*/ RECT frameRect; frameRect.left = rect->left; @@ -445,7 +417,6 @@ void Surface2Surface(int x, int y, const RECT *rect, int to, int from) ScaleRect(rect, &frameRect); Backend_Blit(surf[from].backend, &frameRect, surf[to].backend, x * magnification, y * magnification, TRUE); - //surf[to].needs_updating = TRUE; } unsigned long GetCortBoxColor(unsigned long col) @@ -481,7 +452,6 @@ void CortBox2(const RECT *rect, unsigned long col, Surface_Ids surf_no) const unsigned char col_blue = (unsigned char)((col >> 16) & 0xFF); Backend_ColourFill(surf[surf_no].backend, &destRect, col_red, col_green, col_blue); - //surf[surf_no].needs_updating = TRUE; } #ifdef WINDOWS @@ -591,7 +561,6 @@ void PutText(int x, int y, const char *text, unsigned long color) void PutText2(int x, int y, const char *text, unsigned long color, Surface_Ids surf_no) { Backend_DrawText(surf[surf_no].backend, gFont, x * magnification, y * magnification, text, color); - //surf[surf_no].needs_updating = TRUE; } void EndTextObject() From b84661d88ae69f30e9ade7af6422870d5c590a85 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 15 Jul 2019 17:01:42 +0100 Subject: [PATCH 005/128] Move the backend files around a bit --- CMakeLists.txt | 4 ++-- src/Backends/{ => Rendering}/SDLTexture.cpp | 6 +++--- src/Backends/{SDLSoftware.cpp => Rendering/Software.cpp} | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) rename src/Backends/{ => Rendering}/SDLTexture.cpp (98%) rename src/Backends/{SDLSoftware.cpp => Rendering/Software.cpp} (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5efe064e..540077e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,9 +247,9 @@ if(NONPORTABLE) endif() if(RENDERER MATCHES "Texture") - target_sources(CSE2 PRIVATE "src/Backends/SDLTexture.cpp") + target_sources(CSE2 PRIVATE "src/Backends/Rendering/SDLTexture.cpp") elseif(RENDERER MATCHES "Software") - target_sources(CSE2 PRIVATE "src/Backends/SDLSoftware.cpp") + target_sources(CSE2 PRIVATE "src/Backends/Rendering/Software.cpp") endif() # Make some tweaks if we're targetting Windows diff --git a/src/Backends/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp similarity index 98% rename from src/Backends/SDLTexture.cpp rename to src/Backends/Rendering/SDLTexture.cpp index f4475397..4fc4a004 100644 --- a/src/Backends/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -1,13 +1,13 @@ -#include "Rendering.h" +#include "../Rendering.h" #include #include #include "SDL.h" -#include "../WindowsWrapper.h" +#include "../../WindowsWrapper.h" -#include "../Font.h" +#include "../../Font.h" struct Backend_Surface { diff --git a/src/Backends/SDLSoftware.cpp b/src/Backends/Rendering/Software.cpp similarity index 98% rename from src/Backends/SDLSoftware.cpp rename to src/Backends/Rendering/Software.cpp index b9ed8b33..2aea1f5b 100644 --- a/src/Backends/SDLSoftware.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -1,13 +1,13 @@ -#include "Rendering.h" +#include "../Rendering.h" #include #include #include "SDL.h" -#include "../WindowsWrapper.h" +#include "../../WindowsWrapper.h" -#include "../Font.h" +#include "../../Font.h" struct Backend_Surface { From 6a4f4e0df32eb1790986ac0871d4e8fd2c608c05 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 15 Jul 2019 17:47:22 +0100 Subject: [PATCH 006/128] Added handlers for render target loss/window resize These only really happen when you use exclusive fullscreen and alt-tab out. Or, at least, it does on Windows with SDL2 in DirectX mode. --- src/Backends/Rendering.h | 2 ++ src/Backends/Rendering/SDLTexture.cpp | 27 +++++++++++++++++++++++++++ src/Backends/Rendering/Software.cpp | 19 +++++++++++++++---- src/Draw.cpp | 10 ++++++++++ src/Draw.h | 2 ++ src/Main.cpp | 10 ++++++++++ 6 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index 9416c958..12c2d5e9 100644 --- a/src/Backends/Rendering.h +++ b/src/Backends/Rendering.h @@ -21,3 +21,5 @@ void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned ch void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect); void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour); void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour); +void Backend_HandleDeviceLoss(void); +void Backend_HandleWindowResize(void); diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 4fc4a004..852fd519 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -14,11 +14,16 @@ struct Backend_Surface BOOL needs_syncing; SDL_Surface *sdl_surface; SDL_Texture *texture; + + struct Backend_Surface *next; + struct Backend_Surface *prev; }; static SDL_Renderer *renderer; static SDL_Texture *screen_texture; +static Backend_Surface *surface_list_head; + static void FlushSurface(Backend_Surface *surface) { unsigned char *buffer = (unsigned char*)malloc(surface->sdl_surface->w * surface->sdl_surface->h * 4); @@ -120,11 +125,21 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) surface->needs_syncing = FALSE; + surface->next = surface_list_head; + if (surface->next) + surface->next->prev = surface; + surface_list_head = surface; + return surface; } void Backend_FreeSurface(Backend_Surface *surface) { + if (surface->next) + surface->next->prev = surface->prev; + if (surface->prev) + surface->prev->next = surface->next; + SDL_FreeSurface(surface->sdl_surface); free(surface); } @@ -274,3 +289,15 @@ void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_DestroyTexture(texture); } + +void Backend_HandleDeviceLoss(void) +{ + // All of our textures have been lost, so regenerate them + for (Backend_Surface *surface = surface_list_head; surface != NULL; surface = surface->next) + surface->needs_syncing = TRUE; +} + +void Backend_HandleWindowResize(void) +{ + // No problem for us +} diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 2aea1f5b..8ae95281 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -83,10 +83,10 @@ 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) { - for (unsigned int h = 0; h < height; ++h) + for (unsigned int i = 0; i < height; ++i) { - const unsigned char *src_row = &pixels[h * pitch]; - unsigned char *dst_row = &surface->pixels[h * surface->pitch]; + const unsigned char *src_row = &pixels[i * pitch]; + unsigned char *dst_row = &surface->pixels[i * surface->pitch]; memcpy(dst_row, src_row, width * 3); } @@ -231,10 +231,21 @@ void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour) { DrawText(font, surface->pixels, surface->pitch, surface->width, surface->height, x, y, colour, text, strlen(text)); - //surf[surf_no].needs_updating = TRUE; } void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour) { Backend_DrawText(&framebuffer, font, x, y, text, colour); } + +void Backend_HandleDeviceLoss(void) +{ + // No problem for us +} + +void Backend_HandleWindowResize(void) +{ + // https://wiki.libsdl.org/SDL_GetWindowSurface + // We need to fetch a new surface pointer + window_surface = SDL_GetWindowSurface(window); +} diff --git a/src/Draw.cpp b/src/Draw.cpp index 8d81b01e..3bf6c3da 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -569,3 +569,13 @@ void EndTextObject() UnloadFont(gFont); gFont = NULL; } + +void HandleDeviceLoss() +{ + Backend_HandleDeviceLoss(); +} + +void HandleWindowResize() +{ + Backend_HandleWindowResize(); +} diff --git a/src/Draw.h b/src/Draw.h index d50bef34..e7e537b8 100644 --- a/src/Draw.h +++ b/src/Draw.h @@ -72,3 +72,5 @@ void InitTextObject(const char *font_name); void PutText(int x, int y, const char *text, unsigned long color); void PutText2(int x, int y, const char *text, unsigned long color, Surface_Ids surf_no); void EndTextObject(); +void HandleDeviceLoss(); +void HandleWindowResize(); diff --git a/src/Main.cpp b/src/Main.cpp index ea6fc2fc..f3b98f7a 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -463,9 +463,19 @@ BOOL SystemTask() return FALSE; break; + case SDL_RENDER_TARGETS_RESET: + case SDL_RENDER_DEVICE_RESET: + HandleDeviceLoss(); + break; + case SDL_WINDOWEVENT: switch (event.window.event) { + case SDL_WINDOWEVENT_RESIZED: + case SDL_WINDOWEVENT_SIZE_CHANGED: + HandleWindowResize(); + break; + case SDL_WINDOWEVENT_FOCUS_GAINED: focusGained = TRUE; ActiveWindow(); From 8fb3f302a098bed2bc10021fc9d9d47ae78ad9a5 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 15 Jul 2019 17:58:33 +0100 Subject: [PATCH 007/128] Got the Makefile working again, and updated the readme --- Makefile | 9 +++++++++ README.md | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/Makefile b/Makefile index 3c4bb65b..a732774b 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,9 @@ NATIVECXX = c++ BUILD_DIRECTORY = game ASSETS_DIRECTORY = assets +# Default options +RENDERER ?= Texture + ifeq ($(RELEASE), 1) CXXFLAGS = -O3 -flto LDFLAGS = -s @@ -202,6 +205,12 @@ ifneq ($(WINDOWS), 1) RESOURCES += ICON/ICON_MINI.bmp endif +ifeq ($(RENDERER), Texture) + SOURCES += Backends/Rendering/SDLTexture.cpp +else ifeq ($(RENDERER), Software) + SOURCES += Backends/Rendering/Software.cpp +endif + OBJECTS = $(addprefix obj/$(FILENAME)/, $(addsuffix .o, $(SOURCES))) DEPENDENCIES = $(addprefix obj/$(FILENAME)/, $(addsuffix .o.d, $(SOURCES))) diff --git a/README.md b/README.md index b05ead4e..c9c734f6 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ You can also add the following flags: * `-DFIX_BUGS=ON` - Fix bugs in the game (see [src/Bug Fixes.txt](src/Bug%20Fixes.txt)) * `-DNONPORTABLE=ON` - Enable bits of code that aren't portable, but are what the original game used * `-DFORCE_LOCAL_LIBS=ON` - Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones +* `-DRENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default) +* `-DRENDERER=Software` - Use the software renderer Then compile CSE2 with this command: @@ -53,6 +55,8 @@ Run 'make' in this folder, preferably with some of the following settings: * `WINDOWS=1` - Enable Windows-only features like a unique file/taskbar icon, and system font loading (needed for the font setting in Config.dat to do anything) * `RASPBERRY_PI=1` - Enable tweaks to improve performance on Raspberry Pis * `NONPORTABLE=1` - Enable bits of code that aren't portable, but are what the original game used +* `RENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default) +* `RENDERER=Software` - Use the software renderer ### Visual Studio .NET 2003 From 9eaba52cafcac7c2f3bfc72d7be1f15893196be1 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 15 Jul 2019 18:08:15 +0000 Subject: [PATCH 008/128] Actually fix the Makefile Sorry, couldn't test the last commit because I was on a Windows machine without MSYS2 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a732774b..86e4f5cb 100644 --- a/Makefile +++ b/Makefile @@ -206,9 +206,9 @@ ifneq ($(WINDOWS), 1) endif ifeq ($(RENDERER), Texture) - SOURCES += Backends/Rendering/SDLTexture.cpp + SOURCES += Backends/Rendering/SDLTexture else ifeq ($(RENDERER), Software) - SOURCES += Backends/Rendering/Software.cpp + SOURCES += Backends/Rendering/Software endif OBJECTS = $(addprefix obj/$(FILENAME)/, $(addsuffix .o, $(SOURCES))) From a679373c14df49ec7fe3b0ce7377290556667112 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 15 Jul 2019 18:20:24 +0000 Subject: [PATCH 009/128] Disable font anti-aliasing when FIX_BUGS is enabled It causes ugly artifacting around the text --- src/Font.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Font.cpp b/src/Font.cpp index 4ce46010..210e2124 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -14,8 +14,16 @@ #include "File.h" -// Uncomment for that authentic pre-Windows Vista feel -//#define DISABLE_FONT_ANTIALIASING +// Cave Story wasn't intended to use font anti-aliasing. It's only because Microsoft enabled it +// by default from Windows Vista onwards that the game started using it. +// Font anti-aliasing conflicts with the game's colour-keying, causing ugly artifacting around +// the text in numerous cases. +// The only way to 'fix' the artifacting is to convert the entire drawing system to use alpha +// blending instead of colour-keying, which is way out of scope for a simple compile flag, so +// instead we just disable the anti-aliasing entirely. It's how it was meant to be anyway. +#ifdef FIX_BUGS +#define DISABLE_FONT_ANTIALIASING +#endif #undef MIN #undef MAX From 81eb438482f176526e7d4e0de6d21be49580a27a Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 16 Jul 2019 00:15:20 +0100 Subject: [PATCH 010/128] Fixes and tweaks --- src/Backends/Rendering/SDLTexture.cpp | 4 +++- src/Backends/Rendering/Software.cpp | 12 ++++++++++++ src/Draw.cpp | 8 ++++---- src/Main.cpp | 1 - 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 852fd519..ddc74248 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -86,6 +86,7 @@ BOOL Backend_Init(SDL_Window *window) void Backend_Deinit(void) { + SDL_DestroyTexture(screen_texture); SDL_DestroyRenderer(renderer); } @@ -126,9 +127,10 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) surface->needs_syncing = FALSE; surface->next = surface_list_head; + surface->prev = NULL; + surface_list_head = surface; if (surface->next) surface->next->prev = surface; - surface_list_head = surface; return surface; } diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 8ae95281..4978c018 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -130,6 +130,12 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur rect_clamped.bottom -= overflow; } + if (rect_clamped.bottom - rect_clamped.top <= 0) + return; + + if (rect_clamped.right - rect_clamped.left <= 0) + return; + // Do the actual blitting if (colour_key) { @@ -205,6 +211,12 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha rect_clamped.bottom -= overflow; } + if (rect_clamped.bottom - rect_clamped.top <= 0) + return; + + if (rect_clamped.right - rect_clamped.left <= 0) + return; + for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) { unsigned char *source_pointer = &surface->pixels[((rect_clamped.top + j) * surface->pitch) + (rect_clamped.left * 3)]; diff --git a/src/Draw.cpp b/src/Draw.cpp index 3bf6c3da..283a97af 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -92,24 +92,24 @@ BOOL StartDirectDraw(int lMagnification, int lColourDepth) break; } + rgb24_pixel_format = SDL_AllocFormat(SDL_PIXELFORMAT_RGB24); + // Create renderer if (!Backend_Init(gWindow)) return FALSE; - rgb24_pixel_format = SDL_AllocFormat(SDL_PIXELFORMAT_RGB24); - return TRUE; } void EndDirectDraw() { - SDL_FreeFormat(rgb24_pixel_format); - // Release all surfaces for (int i = 0; i < SURFACE_ID_MAX; i++) ReleaseSurface(i); Backend_Deinit(); + + SDL_FreeFormat(rgb24_pixel_format); } static BOOL IsEnableBitmap(SDL_RWops *fp) diff --git a/src/Main.cpp b/src/Main.cpp index f3b98f7a..171eca8d 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -298,7 +298,6 @@ int main(int argc, char *argv[]) StartDirectDraw(2, colourDepth); - fullscreen = TRUE; SDL_ShowCursor(0); break; } From 7c12e7817cfd69ecbc0bc330004adcc1ac1c7252 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 16 Jul 2019 00:37:31 +0100 Subject: [PATCH 011/128] Use SDL_ALPHA_OPAQUE --- src/Backends/Rendering/SDLTexture.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index ddc74248..5a461374 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -213,7 +213,7 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha if (red == 0 && green == 0 && blue == 0) SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); else - SDL_SetRenderDrawColor(renderer, red, green, blue, 0xFF); + SDL_SetRenderDrawColor(renderer, red, green, blue, SDL_ALPHA_OPAQUE); // Draw colour SDL_SetRenderTarget(renderer, surface->texture); @@ -229,7 +229,7 @@ void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned ch RectToSDLRect(rect, &sdl_rect); // Draw colour - SDL_SetRenderDrawColor(renderer, red, green, blue, 0xFF); + SDL_SetRenderDrawColor(renderer, red, green, blue, SDL_ALPHA_OPAQUE); SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); SDL_RenderFillRect(renderer, &sdl_rect); SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); From 6c7d49ad503190f943380f36812c7128453710c1 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 16 Jul 2019 12:25:22 +0000 Subject: [PATCH 012/128] Added DoConfig to the Makefile --- Makefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 86e4f5cb..af9ee0a6 100644 --- a/Makefile +++ b/Makefile @@ -11,9 +11,11 @@ ifeq ($(RELEASE), 1) CXXFLAGS = -O3 -flto LDFLAGS = -s FILENAME_DEF = CSE2 + DOCONFIG_FILENAME_DEF = DoConfig else CXXFLAGS = -Og -g3 FILENAME_DEF = CSE2_debug + DOCONFIG_FILENAME_DEF = DoConfig_debug endif ifeq ($(JAPANESE), 1) @@ -25,6 +27,7 @@ else endif FILENAME ?= $(FILENAME_DEF) +DOCONFIG_FILENAME ?= $(DOCONFIG_FILENAME_DEF) ifeq ($(FIX_BUGS), 1) CXXFLAGS += -DFIX_BUGS @@ -218,7 +221,7 @@ ifeq ($(WINDOWS), 1) OBJECTS += obj/$(FILENAME)/win_icon.o endif -all: $(BUILD_DIRECTORY)/$(FILENAME) $(BUILD_DIRECTORY)/data +all: $(BUILD_DIRECTORY)/$(FILENAME) $(BUILD_DIRECTORY)/data $(BUILD_DIRECTORY)/$(DOCONFIG_FILENAME) @echo Finished $(BUILD_DIRECTORY)/data: $(DATA_DIRECTORY) @@ -257,6 +260,15 @@ obj/$(FILENAME)/win_icon.o: $(ASSETS_DIRECTORY)/resources/ICON/ICON.rc $(ASSETS_ @mkdir -p $(@D) @windres $< $@ +$(BUILD_DIRECTORY)/$(DOCONFIG_FILENAME): DoConfig/DoConfig.cpp + @mkdir -p $(@D) + @echo Linking $@ +ifeq ($(STATIC), 1) + @$(CXX) -O3 -s -std=c++98 -static $^ -o $@ `fltk-config --cxxflags --libs --ldstaticflags` +else + @$(CXX) -O3 -s -std=c++98 $^ -o $@ `fltk-config --cxxflags --libs --ldflags` +endif + # TODO clean: @rm -rf obj From 36fdb4596d2be7e3ae7a6749bc8f433f3a676864 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 16 Jul 2019 13:21:21 +0100 Subject: [PATCH 013/128] Cleanup and an accuracy improvement --- src/Draw.cpp | 1 - src/Main.cpp | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index 283a97af..20e6569a 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -250,7 +250,6 @@ static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface) } SDL_FreeSurface(converted_surface); - //surf[surf_no].needs_updating = TRUE; printf(" ^ Successfully loaded\n"); success = TRUE; } diff --git a/src/Main.cpp b/src/Main.cpp index 171eca8d..b785164f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -208,7 +208,7 @@ int main(int argc, char *argv[]) } } - RECT unused_rect = {0, 0, 320, 240}; + RECT unused_rect = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; // Load cursor size_t size; @@ -265,7 +265,6 @@ int main(int argc, char *argv[]) StartDirectDraw(0, 0); else StartDirectDraw(1, 0); - break; } break; @@ -299,8 +298,8 @@ int main(int argc, char *argv[]) StartDirectDraw(2, colourDepth); SDL_ShowCursor(0); - break; } + break; } @@ -338,7 +337,7 @@ int main(int argc, char *argv[]) // Set rects RECT loading_rect = {0, 0, 64, 8}; - RECT clip_rect = {0, 0, windowWidth, windowHeight}; + RECT clip_rect = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; // Load the "LOADING" text MakeSurface_File("Loading", SURFACE_ID_LOADING); From f21f17f4c2fd8c4ba4d1fcf1dcf0976fd1d251ab Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 17 Jul 2019 14:13:49 +0100 Subject: [PATCH 014/128] Cleanup --- src/Backends/Rendering/SDLTexture.cpp | 18 +++++++++--------- src/Backends/Rendering/Software.cpp | 24 +++++++++++++----------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 5a461374..543a377b 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -30,20 +30,20 @@ static void FlushSurface(Backend_Surface *surface) unsigned char *buffer_pointer = buffer; // Convert the SDL_Surface's colour-keyed pixels to RGBA32 - for (int h = 0; h < surface->sdl_surface->h; ++h) + for (int y = 0; y < surface->sdl_surface->h; ++y) { - unsigned char *src_pixel = (unsigned char*)surface->sdl_surface->pixels + (h * surface->sdl_surface->pitch); + unsigned char *src_pixel = (unsigned char*)surface->sdl_surface->pixels + (y * surface->sdl_surface->pitch); - for (int w = 0; w < surface->sdl_surface->w; ++w) + for (int x = 0; x < surface->sdl_surface->x; ++x) { *buffer_pointer++ = src_pixel[0]; *buffer_pointer++ = src_pixel[1]; *buffer_pointer++ = src_pixel[2]; - if (src_pixel[0] != 0 || src_pixel[1] != 0 || src_pixel[2] != 0) // Assumes the colour key will always be #00000000 (black) - *buffer_pointer++ = 0xFF; - else + if (src_pixel[0] == 0 && src_pixel[1] == 0 && src_pixel[2] == 0) // Assumes the colour key will always be #000000 (black) *buffer_pointer++ = 0; + else + *buffer_pointer++ = 0xFF; src_pixel += 3; } @@ -148,10 +148,10 @@ 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) { - for (unsigned int h = 0; h < height; ++h) + for (unsigned int i = 0; i < height; ++i) { - const unsigned char *src_row = &pixels[h * pitch]; - unsigned char *dst_row = (unsigned char*)surface->sdl_surface->pixels + h * surface->sdl_surface->pitch; + 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); } diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 4978c018..77bd5d7f 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -146,15 +146,17 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur for (long i = 0; i < rect_clamped.right - rect_clamped.left; ++i) { - if (source_pointer[0] != 0 || source_pointer[1] != 0 || source_pointer[2] != 0) // Assumes the colour key will always be #00000000 (black) + if (source_pointer[0] == 0 && source_pointer[1] == 0 && source_pointer[2] == 0) // Assumes the colour key will always be #000000 (black) { - destination_pointer[0] = source_pointer[0]; - destination_pointer[1] = source_pointer[1]; - destination_pointer[2] = source_pointer[2]; + source_pointer += 3; + destination_pointer += 3; + } + else + { + *destination_pointer++ = *source_pointer++; + *destination_pointer++ = *source_pointer++; + *destination_pointer++ = *source_pointer++; } - - source_pointer += 3; - destination_pointer += 3; } } } @@ -219,13 +221,13 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) { - unsigned char *source_pointer = &surface->pixels[((rect_clamped.top + j) * surface->pitch) + (rect_clamped.left * 3)]; + unsigned char *destination_pointer = &surface->pixels[((rect_clamped.top + j) * surface->pitch) + (rect_clamped.left * 3)]; for (long i = 0; i < rect_clamped.right - rect_clamped.left; ++i) { - *source_pointer++ = red; - *source_pointer++ = green; - *source_pointer++ = blue; + *destination_pointer++ = red; + *destination_pointer++ = green; + *destination_pointer++ = blue; } } } From 44456e4a258d21e286b5a7ee697e45dc5f201870 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 17 Jul 2019 16:09:18 +0100 Subject: [PATCH 015/128] Add an SDL_Surface-based renderer Ha, my custom software renderer is faster! --- CMakeLists.txt | 6 +++++- Makefile | 4 ++++ README.md | 8 ++++++-- src/Backends/Rendering.h | 2 +- src/Backends/Rendering/SDLTexture.cpp | 4 ++-- src/Backends/Rendering/Software.cpp | 2 +- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 540077e2..337312eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ option(JAPANESE "Enable the Japanese-language build" OFF) option(FIX_BUGS "Fix certain bugs (see src/Bug Fixes.txt)" OFF) option(NONPORTABLE "Enable bits of code that aren't portable, but are what the original game used" OFF) option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF) -set(RENDERER "Texture" CACHE STRING "Which renderer the game should use: 'Texture' for SDL2's hardware-accelerated Texture API, and 'Software' for a handwritten software renderer") +set(RENDERER "Texture" CACHE STRING "Which renderer the game should use: 'Texture' for SDL2's hardware-accelerated Texture API, 'Surface' for SDL2's software-rendered Surface API, and 'Software' for a handwritten software renderer") project(CSE2 LANGUAGES C CXX) @@ -248,8 +248,12 @@ endif() if(RENDERER MATCHES "Texture") target_sources(CSE2 PRIVATE "src/Backends/Rendering/SDLTexture.cpp") +elseif(RENDERER MATCHES "Surface") + target_sources(CSE2 PRIVATE "src/Backends/Rendering/SDLSurface.cpp") elseif(RENDERER MATCHES "Software") target_sources(CSE2 PRIVATE "src/Backends/Rendering/Software.cpp") +else() + message(FATAL_ERROR "Invalid RENDERER selected") endif() # Make some tweaks if we're targetting Windows diff --git a/Makefile b/Makefile index af9ee0a6..c13e163d 100644 --- a/Makefile +++ b/Makefile @@ -210,8 +210,12 @@ endif ifeq ($(RENDERER), Texture) SOURCES += Backends/Rendering/SDLTexture +else ifeq ($(RENDERER), Surface) + SOURCES += Backends/Rendering/Software else ifeq ($(RENDERER), Software) SOURCES += Backends/Rendering/Software +else + @echo Invalid RENDERER selected; this build will fail endif OBJECTS = $(addprefix obj/$(FILENAME)/, $(addsuffix .o, $(SOURCES))) diff --git a/README.md b/README.md index c9c734f6..dc05e23c 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,10 @@ You can also add the following flags: * `-DNONPORTABLE=ON` - Enable bits of code that aren't portable, but are what the original game used * `-DFORCE_LOCAL_LIBS=ON` - Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones * `-DRENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default) -* `-DRENDERER=Software` - Use the software renderer +* `-DRENDERER=Surface` - Use SDL2's software-renderer Surface API +* `-DRENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default) +* `-DRENDERER=Surface` - Use the software-rendered SDL2 Surface API renderer +* `-DRENDERER=Software` - Use a handwritten software renderer Then compile CSE2 with this command: @@ -56,7 +59,8 @@ Run 'make' in this folder, preferably with some of the following settings: * `RASPBERRY_PI=1` - Enable tweaks to improve performance on Raspberry Pis * `NONPORTABLE=1` - Enable bits of code that aren't portable, but are what the original game used * `RENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default) -* `RENDERER=Software` - Use the software renderer +* `RENDERER=Surface` - Use the software-rendered SDL2 Surface API renderer +* `RENDERER=Software` - Use a hand-written software renderer ### Visual Studio .NET 2003 diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index 12c2d5e9..5670ac78 100644 --- a/src/Backends/Rendering.h +++ b/src/Backends/Rendering.h @@ -6,7 +6,7 @@ #include "../Font.h" -struct Backend_Surface; +typedef struct Backend_Surface Backend_Surface; BOOL Backend_Init(SDL_Window *window); void Backend_Deinit(void); diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 543a377b..a35770e4 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -9,7 +9,7 @@ #include "../../Font.h" -struct Backend_Surface +typedef struct Backend_Surface { BOOL needs_syncing; SDL_Surface *sdl_surface; @@ -17,7 +17,7 @@ struct Backend_Surface struct Backend_Surface *next; struct Backend_Surface *prev; -}; +} Backend_Surface; static SDL_Renderer *renderer; static SDL_Texture *screen_texture; diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 77bd5d7f..6f6f1612 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -15,7 +15,7 @@ struct Backend_Surface unsigned int width; unsigned int height; unsigned int pitch; -}; +} Backend_Surface; static SDL_Window *window; static SDL_Surface *window_surface; From f1e6103a46d27edd3be6cd9c372bc94f2d66a3cb Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 17 Jul 2019 16:35:33 +0100 Subject: [PATCH 016/128] ...Actually add the SDL_Surface renderer file --- src/Backends/Rendering/SDLSurface.cpp | 155 ++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/Backends/Rendering/SDLSurface.cpp diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp new file mode 100644 index 00000000..79218bc0 --- /dev/null +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -0,0 +1,155 @@ +#include "../Rendering.h" + +#include +#include + +#include "SDL.h" + +#include "../../WindowsWrapper.h" + +#include "../../Font.h" + +typedef struct Backend_Surface +{ + SDL_Surface *sdl_surface; +} Backend_Surface; + +static SDL_Window *window; +static SDL_Surface *window_surface; + +static Backend_Surface framebuffer; + +static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect) +{ + sdl_rect->x = (int)rect->left; + sdl_rect->y = (int)rect->top; + sdl_rect->w = (int)(rect->right - rect->left); + sdl_rect->h = (int)(rect->bottom - rect->top); + + if (sdl_rect->w < 0) + sdl_rect->w = 0; + + if (sdl_rect->h < 0) + sdl_rect->h = 0; +} + +BOOL Backend_Init(SDL_Window *p_window) +{ + window = p_window; + + window_surface = SDL_GetWindowSurface(window); + + framebuffer.sdl_surface = SDL_CreateRGBSurfaceWithFormat(0, window_surface->w, window_surface->h, 0, SDL_PIXELFORMAT_RGB24); + + if (framebuffer.sdl_surface == NULL) + return FALSE; + + return TRUE; +} + +void Backend_Deinit(void) +{ + SDL_FreeSurface(framebuffer.sdl_surface); +} + +void Backend_DrawScreen(void) +{ + SDL_BlitSurface(framebuffer.sdl_surface, NULL, window_surface, NULL); + SDL_UpdateWindowSurface(window); +} + +Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) +{ + Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); + + if (surface == NULL) + return NULL; + + surface->sdl_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, SDL_PIXELFORMAT_RGB24); + + if (surface->sdl_surface == NULL) + { + free(surface); + return NULL; + } + + return surface; +} + +void Backend_FreeSurface(Backend_Surface *surface) +{ + SDL_FreeSurface(surface->sdl_surface); + free(surface); +} + +void Backend_LoadPixels(Backend_Surface *surface, const unsigned char *pixels, unsigned int width, unsigned int height, 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); + } +} + +void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) +{ + SDL_Rect source_rect; + RectToSDLRect(rect, &source_rect); + + SDL_Rect destination_rect; + destination_rect.x = x; + destination_rect.y = y; + destination_rect.w = source_rect.w; + destination_rect.h = source_rect.h; + + SDL_SetColorKey(source_surface->sdl_surface, colour_key ? SDL_TRUE : SDL_FALSE, SDL_MapRGB(source_surface->sdl_surface->format, 0, 0, 0)); // Assumes the colour key will always be #000000 (black) + + SDL_BlitSurface(source_surface->sdl_surface, &source_rect, destination_surface->sdl_surface, &destination_rect); +} + +void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) +{ + Backend_Blit(source_surface, rect, &framebuffer, x, y, colour_key); +} + +void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +{ + SDL_Rect destination_rect; + RectToSDLRect(rect, &destination_rect); + + SDL_FillRect(surface->sdl_surface, &destination_rect, SDL_MapRGB(surface->sdl_surface->format, red, green, blue)); +} + +void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +{ + Backend_ColourFill(&framebuffer, rect, red, green, blue); +} + +void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) +{ + Backend_Blit(&framebuffer, rect, surface, rect->left, rect->top, FALSE); +} + +void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour) +{ + DrawText(font, (unsigned char*)surface->sdl_surface->pixels, surface->sdl_surface->pitch, surface->sdl_surface->w, surface->sdl_surface->h, x, y, colour, text, strlen(text)); +} + +void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour) +{ + Backend_DrawText(&framebuffer, font, x, y, text, colour); +} + +void Backend_HandleDeviceLoss(void) +{ + // No problem for us +} + +void Backend_HandleWindowResize(void) +{ + // https://wiki.libsdl.org/SDL_GetWindowSurface + // We need to fetch a new surface pointer + window_surface = SDL_GetWindowSurface(window); +} From 2fe0c44971a17df513ac2d2d4b26ea8d99ecba45 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 17 Jul 2019 16:40:18 +0100 Subject: [PATCH 017/128] Fix readme derp Thanks, Fayti1703 --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index dc05e23c..a273e032 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,6 @@ You can also add the following flags: * `-DNONPORTABLE=ON` - Enable bits of code that aren't portable, but are what the original game used * `-DFORCE_LOCAL_LIBS=ON` - Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones * `-DRENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default) -* `-DRENDERER=Surface` - Use SDL2's software-renderer Surface API -* `-DRENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default) * `-DRENDERER=Surface` - Use the software-rendered SDL2 Surface API renderer * `-DRENDERER=Software` - Use a handwritten software renderer From 74c9931ebbfb73c013a808c17e07f277752dc2d3 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 19 Jul 2019 08:45:59 +0100 Subject: [PATCH 018/128] 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. --- src/Backends/Rendering.h | 3 ++- src/Backends/Rendering/SDLSurface.cpp | 14 +++++++------- src/Backends/Rendering/SDLTexture.cpp | 16 +++++++--------- src/Backends/Rendering/Software.cpp | 16 ++++++++-------- src/Draw.cpp | 27 ++++++++++++++++----------- 5 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index 5670ac78..e3632006 100644 --- a/src/Backends/Rendering.h +++ b/src/Backends/Rendering.h @@ -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); diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 79218bc0..c7e173f6 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -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) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index a35770e4..0c962888 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -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; } diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 6f6f1612..66d22946 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -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) diff --git a/src/Draw.cpp b/src/Draw.cpp index 20e6569a..c8f7a32c 100644 --- a/src/Draw.cpp +++ b/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; From 24d104e2e812a91f3e1d7e4b4dc8b5adf8a74fbc Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 19 Jul 2019 09:02:17 +0100 Subject: [PATCH 019/128] Tweak in Font.cpp MSVC2003 would complain about that code because it didn't understand the C++ standard. It looked ugly anyway. --- src/Font.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Font.cpp b/src/Font.cpp index 210e2124..d780611f 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -1715,11 +1715,13 @@ static unsigned long UTF8ToUnicode(const unsigned char *string, unsigned int *by static CachedGlyph* GetGlyphCached(FontObject *font_object, unsigned long unicode_value) { - for (CachedGlyph *glyph = font_object->glyph_list_head; glyph != NULL; glyph = glyph->next) + CachedGlyph *glyph; + + for (glyph = font_object->glyph_list_head; glyph != NULL; glyph = glyph->next) if (glyph->unicode_value == unicode_value) return glyph; - CachedGlyph *glyph = (CachedGlyph*)malloc(sizeof(CachedGlyph)); + glyph = (CachedGlyph*)malloc(sizeof(CachedGlyph)); if (glyph) { From a3278a60b5c56d1e3305bdcb4665fba7b141651b Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 19 Jul 2019 19:19:35 +0100 Subject: [PATCH 020/128] A fix, some documentation, and cleanup --- src/Draw.cpp | 2 +- src/TextScr.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index c8f7a32c..65a01e24 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -181,7 +181,7 @@ static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface) if (surf_no >= SURFACE_ID_MAX) { - printf("Tried to load bitmap at invalid slot (%d - maximum is %d\n", surf_no, SURFACE_ID_MAX); + printf("Tried to load bitmap at invalid slot (%d - maximum is %d)\n", surf_no, SURFACE_ID_MAX); } else { diff --git a/src/TextScr.cpp b/src/TextScr.cpp index 2669e7a0..c6135890 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -43,7 +43,7 @@ TEXT_SCRIPT gTS; -int gNumberTextScript[4]; +int gNumberTextScript[4]; // Seems to be for debugging char text[0x100]; RECT gRect_line = {0, 0, 216, 16}; @@ -637,8 +637,14 @@ int TextScriptProc() { w = GetTextScriptNo(gTS.p_read + 4); x = GetTextScriptNo(gTS.p_read + 9); + + // Looks like Pixel left some debug code in. Oops. gNumberTextScript[0] = x; + #ifndef FIX_BUGS + // z is uninitialised. Probably a leftover from copypasting. gNumberTextScript[1] = z; + #endif + PlaySoundObject(38, 1); AddArmsData(w, x); gTS.p_read += 13; @@ -1211,6 +1217,11 @@ int TextScriptProc() } else if (IS_COMMAND('N','U','M')) { + // This seems to be a command used for debugging TSC scripts: + // It prints a selected char in the gNumberTextScript array. + // gNumberTextScript is only used by the ' Date: Mon, 22 Jul 2019 21:59:52 +0000 Subject: [PATCH 021/128] Added OpenGL 2.1 renderer Yay 100% hardware-acceleration. Yes, I know 2.1 is outdated and crappy, but it was the easiest one to write. I'll probably make an OpenGL 3.0 Core renderer at some point. Anyway, font rendering isn't here yet, because I plan to overhaul it. --- CMakeLists.txt | 9 +- src/Backends/Rendering/OpenGL2.cpp | 322 +++++++++++++++++++++++++++++ src/Main.cpp | 6 +- 3 files changed, 335 insertions(+), 2 deletions(-) create mode 100644 src/Backends/Rendering/OpenGL2.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 337312eb..1cb934a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,7 +246,9 @@ if(NONPORTABLE) target_compile_definitions(CSE2 PRIVATE NONPORTABLE) endif() -if(RENDERER MATCHES "Texture") +if(RENDERER MATCHES "OpenGL2") + target_sources(CSE2 PRIVATE "src/Backends/Rendering/OpenGL2.cpp") +elseif(RENDERER MATCHES "Texture") target_sources(CSE2 PRIVATE "src/Backends/Rendering/SDLTexture.cpp") elseif(RENDERER MATCHES "Surface") target_sources(CSE2 PRIVATE "src/Backends/Rendering/SDLSurface.cpp") @@ -402,6 +404,11 @@ else() target_link_libraries(CSE2 freetype) endif() +find_package(GLEW REQUIRED) +target_link_libraries(CSE2 GLEW::GLEW) +find_package(OpenGL REQUIRED) +target_link_libraries(CSE2 OpenGL::GL OpenGL::GLU) + ## # DoConfig diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp new file mode 100644 index 00000000..c77688be --- /dev/null +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -0,0 +1,322 @@ +#include "../Rendering.h" + +#include +#include + +#include +#include "SDL.h" + +#include "../../WindowsWrapper.h" + +#include "../../Font.h" + +typedef struct Backend_Surface +{ + GLuint texture_id; + unsigned int width; + unsigned int height; + unsigned char *pixels; +} Backend_Surface; + +static SDL_Window *window; +static SDL_GLContext context; +static GLuint colour_key_program_id; +static GLuint framebuffer_id; + +static Backend_Surface framebuffer_surface; + +static const GLchar *fragment_shader_source = " \ +#version 120\n \ +uniform sampler2D tex; \ +void main() \ +{ \ + vec4 colour = gl_Color * texture2D(tex, gl_TexCoord[0].st); \ +\ + if (colour.xyz == vec3(0.0f, 0.0f, 0.0f)) \ + discard; \ +\ + gl_FragColor = colour; \ +} \ +"; + +static GLuint CompileShader(const char *fragment_shader_source) +{ + GLint shader_status; + + GLuint program_id = glCreateProgram(); + + GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(fragment_shader, 1, &fragment_shader_source, NULL); + glCompileShader(fragment_shader); + + glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &shader_status); + if (shader_status != GL_TRUE) + return 0; + + glAttachShader(program_id, fragment_shader); + + glLinkProgram(program_id); + + glGetProgramiv(program_id, GL_LINK_STATUS, &shader_status); + if (shader_status != GL_TRUE) + return 0; + + return program_id; +} + +BOOL Backend_Init(SDL_Window *p_window) +{ + window = p_window; + + int screen_width, screen_height; + SDL_GetWindowSize(window, &screen_width, &screen_height); + + context = SDL_GL_CreateContext(window); + + if (glewInit() != GLEW_OK) + return FALSE; + + // Check for framebuffer object extension (is part of the core spec in OpenGL 3.0, but not 2.1) + if (!GLEW_EXT_framebuffer_object) + return FALSE; + +// glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glOrtho(0.0, screen_width, 0.0, screen_height, 1.0, -1.0); + +// glMatrixMode(GL_PROJECTION); +// glLoadIdentity(); + + glEnable(GL_TEXTURE_2D); + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + // Set up blank default texture (it seems to be black by default, which sucks for colour modulation) + const unsigned char white_pixel[3] = {0xFF, 0xFF, 0xFF}; + glBindTexture(GL_TEXTURE_2D, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, white_pixel); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + // Set up our colour-key-enabled fragment shader + colour_key_program_id = CompileShader(fragment_shader_source); + + // Set up framebuffer (used for surface-to-surface blitting) + glGenFramebuffersEXT(1, &framebuffer_id); + + // Set up framebuffer screen texture (used for screen-to-surface blitting) + glGenTextures(1, &framebuffer_surface.texture_id); + glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screen_width, screen_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + framebuffer_surface.width = screen_width; + framebuffer_surface.height = screen_height; + + return TRUE; +} + +void Backend_Deinit(void) +{ + glDeleteTextures(1, &framebuffer_surface.texture_id); + glDeleteFramebuffersEXT(1, &framebuffer_id); + glDeleteProgram(colour_key_program_id); + SDL_GL_DeleteContext(context); +} + +void Backend_DrawScreen(void) +{ + // Disable colour-keying + glUseProgram(0); + + // Target actual screen, and not our framebuffer + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + + // Draw framebuffer to screen + glPushMatrix(); + glLoadIdentity(); + + glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id); + + glBegin(GL_QUADS); + glColor3f(1.0f, 1.0f, 1.0f); + glTexCoord2f(0.0f, 1.0f); + glVertex2f(-1.0f, -1.0f); + glTexCoord2f(1.0f, 1.0f); + glVertex2f(1.0f, -1.0f); + glTexCoord2f(1.0f, 0.0f); + glVertex2f(1.0f, 1.0f); + glTexCoord2f(0.0f, 0.0f); + glVertex2f(-1.0f, 1.0f); + glEnd(); + + glPopMatrix(); + + SDL_GL_SwapWindow(window); + + // According to https://www.khronos.org/opengl/wiki/Common_Mistakes#Swap_Buffers + // the buffer should always be cleared + glClear(GL_COLOR_BUFFER_BIT); + + // Switch back to our framebuffer + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_id); +} + +Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) +{ + Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); + + if (surface == NULL) + return NULL; + + glGenTextures(1, &surface->texture_id); + glBindTexture(GL_TEXTURE_2D, surface->texture_id); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + surface->width = width; + surface->height = height; + + return surface; +} + +void Backend_FreeSurface(Backend_Surface *surface) +{ + glDeleteTextures(1, &surface->texture_id); + free(surface); +} + +unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch) +{ + surface->pixels = (unsigned char*)malloc(surface->width * surface->height * 3); + *pitch = surface->width * 3; + return surface->pixels; +} + +void Backend_Unlock(Backend_Surface *surface) +{ + glBindTexture(GL_TEXTURE_2D, surface->texture_id); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, surface->width, surface->height, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels); + free(surface->pixels); +} + +static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) +{ + // Switch to colour-key shader if we have to + glUseProgram(colour_key ? colour_key_program_id : 0); + + glBindTexture(GL_TEXTURE_2D, source_surface->texture_id); + + glBegin(GL_QUADS); + glColor3f(1.0f, 1.0f, 1.0f); + glTexCoord2f((GLfloat)rect->left / (GLfloat)source_surface->width, (GLfloat)rect->top / (GLfloat)source_surface->height); + glVertex2f((GLfloat)x, (GLfloat)y); + glTexCoord2f((GLfloat)rect->right / (GLfloat)source_surface->width, (GLfloat)rect->top / (GLfloat)source_surface->height); + glVertex2f((GLfloat)x + (rect->right - rect->left), (GLfloat)y); + glTexCoord2f((GLfloat)rect->right / (GLfloat)source_surface->width, (GLfloat)rect->bottom / (GLfloat)source_surface->height); + glVertex2f((GLfloat)x + (rect->right - rect->left), (GLfloat)y + (rect->bottom - rect->top)); + glTexCoord2f((GLfloat)rect->left / (GLfloat)source_surface->width, (GLfloat)rect->bottom / (GLfloat)source_surface->height); + glVertex2f((GLfloat)x, (GLfloat)y + (rect->bottom - rect->top)); + glEnd(); +} + +void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) +{ + // Point our framebuffer to the destination texture + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, destination_surface->texture_id, 0); + + // The matrix needs resetting to fit the dimensions of the destination texture + glPushMatrix(); + glLoadIdentity(); + glOrtho(0.0, destination_surface->width, 0.0, destination_surface->height, 1.0, -1.0); + + BlitCommon(source_surface, rect, x, y, colour_key); + + glPopMatrix(); +} + +void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) +{ + // Point our framebuffer to the screen texture + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + + BlitCommon(source_surface, rect, x, y, colour_key); +} + +static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +{ + // Disable colour-keying + glUseProgram(0); + + // Use blank default texture, for a solid colour-fill + glBindTexture(GL_TEXTURE_2D, 0); + + glBegin(GL_QUADS); + glColor3f(red / 255.0f, green / 255.0f, blue / 255.0f); + glVertex2f((GLfloat)rect->left, (GLfloat)rect->top); + glVertex2f((GLfloat)rect->right, (GLfloat)rect->top); + glVertex2f((GLfloat)rect->right, (GLfloat)rect->bottom); + glVertex2f((GLfloat)rect->left, (GLfloat)rect->bottom); + glEnd(); +} + +void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +{ + // Point our framebuffer to the destination texture + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + + // The matrix needs resetting to fit the dimensions of the destination texture + glPushMatrix(); + glLoadIdentity(); + glOrtho(0.0, surface->width, 0.0, surface->height, 1.0, -1.0); + + ColourFillCommon(rect, red, green, blue); + + glPopMatrix(); +} + +void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +{ + // Point our framebuffer to the screen texture + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + + ColourFillCommon(rect, red, green, blue); +} + +void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) +{ + // Point our framebuffer to the destination texture + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + + // The matrix needs resetting to fit the dimensions of the destination texture + glPushMatrix(); + glLoadIdentity(); + glOrtho(0.0, surface->width, 0.0, surface->height, 1.0, -1.0); + + BlitCommon(&framebuffer_surface, rect, rect->left, rect->top, FALSE); + + glPopMatrix(); +} + +void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour) +{ + // Soon +} + +void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour) +{ + // Soon +} + +void Backend_HandleDeviceLoss(void) +{ + // No problem for us +} + +void Backend_HandleWindowResize(void) +{ + // No problem for us +} diff --git a/src/Main.cpp b/src/Main.cpp index b785164f..9d8fb8f4 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -256,8 +256,12 @@ int main(int argc, char *argv[]) windowHeight = WINDOW_HEIGHT * 2; } + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + // Create window - gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0); + gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, SDL_WINDOW_OPENGL); if (gWindow) { From 90f29377fea8c34ec8b58e5198be322440d564ef Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 23 Jul 2019 15:19:17 +0100 Subject: [PATCH 022/128] Apply some surface ID constants --- src/MiniMap.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MiniMap.cpp b/src/MiniMap.cpp index ce3f4ea1..650bcd68 100644 --- a/src/MiniMap.cpp +++ b/src/MiniMap.cpp @@ -35,7 +35,7 @@ void WriteMiniMapLine(int line) // Yup. This really is an if/else chain. // No switch here. if (a == 0) - Surface2Surface(x, line, &rcLevel[0], 9, 26); + Surface2Surface(x, line, &rcLevel[0], SURFACE_ID_MAP, SURFACE_ID_TEXT_BOX); else if (a == 68 || a == 1 || a == 64 || @@ -57,7 +57,7 @@ void WriteMiniMapLine(int line) a == 161 || a == 162 || a == 163) - Surface2Surface(x, line, &rcLevel[1], 9, 26); + Surface2Surface(x, line, &rcLevel[1], SURFACE_ID_MAP, SURFACE_ID_TEXT_BOX); else if (a == 67 || a == 99 || a == 80 || @@ -69,9 +69,9 @@ void WriteMiniMapLine(int line) a == 115 || a == 116 || a == 119) - Surface2Surface(x, line, &rcLevel[2], 9, 26); + Surface2Surface(x, line, &rcLevel[2], SURFACE_ID_MAP, SURFACE_ID_TEXT_BOX); else - Surface2Surface(x, line, &rcLevel[3], 9, 26); + Surface2Surface(x, line, &rcLevel[3], SURFACE_ID_MAP, SURFACE_ID_TEXT_BOX); } } From 6d385e674fac76cb443d84210269f588d2ea1155 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 23 Jul 2019 16:38:04 +0100 Subject: [PATCH 023/128] Font refactor part 1: Software With this, font blitting is handled by the rendering backend, paving the way for hardware-accelerated font drawing in the accelerated backends. --- src/Backends/Rendering.h | 14 +++- src/Backends/Rendering/Software.cpp | 116 ++++++++++++++++++++++++++-- src/Draw.cpp | 16 ++-- src/Font.cpp | 106 ++++++++----------------- src/Font.h | 4 +- 5 files changed, 167 insertions(+), 89 deletions(-) diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index e3632006..8f2be6e0 100644 --- a/src/Backends/Rendering.h +++ b/src/Backends/Rendering.h @@ -4,9 +4,15 @@ #include "../WindowsWrapper.h" -#include "../Font.h" +enum +{ + FONT_PIXEL_MODE_LCD, + FONT_PIXEL_MODE_GRAY, + FONT_PIXEL_MODE_MONO, +}; typedef struct Backend_Surface Backend_Surface; +typedef struct Backend_Glyph Backend_Glyph; BOOL Backend_Init(SDL_Window *window); void Backend_Deinit(void); @@ -20,7 +26,9 @@ void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, lon void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue); void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue); void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect); -void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour); -void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour); +Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch, unsigned short total_greys, unsigned char pixel_mode); +void Backend_UnloadGlyph(Backend_Glyph *glyph); +void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours); +void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours); void Backend_HandleDeviceLoss(void); void Backend_HandleWindowResize(void); diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 66d22946..25c69bfa 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -7,7 +7,10 @@ #include "../../WindowsWrapper.h" -#include "../../Font.h" +#undef MIN +#undef MAX +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define MAX(a,b) ((a) > (b) ? (a) : (b)) typedef struct Backend_Surface { @@ -17,6 +20,16 @@ typedef struct Backend_Surface unsigned int pitch; } Backend_Surface; +typedef struct Backend_Glyph +{ + unsigned char *pixels; + unsigned int width; + unsigned int height; + int pitch; + unsigned short total_greys; + unsigned char pixel_mode; +} Backend_Glyph; + static SDL_Window *window; static SDL_Surface *window_surface; static SDL_Surface *screen_surface; @@ -242,14 +255,107 @@ void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) Backend_Blit(&framebuffer, rect, surface, rect->left, rect->top, FALSE); } -void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour) +Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch, unsigned short total_greys, unsigned char pixel_mode) { - DrawText(font, surface->pixels, surface->pitch, surface->width, surface->height, x, y, colour, text, strlen(text)); + Backend_Glyph *glyph = (Backend_Glyph*)malloc(sizeof(Backend_Glyph)); + + if (glyph == NULL) + return NULL; + + glyph->pixels = (unsigned char*)malloc(pitch * height); + + if (glyph->pixels == NULL) + { + free(glyph); + return NULL; + } + + memcpy(glyph->pixels, pixels, pitch * height); + + glyph->width = width; + glyph->height = height; + glyph->pitch = pitch; + glyph->total_greys = total_greys; + glyph->pixel_mode = pixel_mode; + + return glyph; } -void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour) +void Backend_UnloadGlyph(Backend_Glyph *glyph) { - Backend_DrawText(&framebuffer, font, x, y, text, colour); + free(glyph->pixels); + free(glyph); +} + +void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) +{ + switch (glyph->pixel_mode) + { + case FONT_PIXEL_MODE_LCD: + for (unsigned int iy = MAX(-y, 0); y + iy < MIN(y + glyph->height, surface->height); ++iy) + { + for (unsigned int ix = MAX(-x, 0); x + ix < MIN(x + glyph->width / 3, surface->width); ++ix) + { + const unsigned char *font_pixel = glyph->pixels + iy * glyph->pitch + ix * 3; + + if (font_pixel[0] || font_pixel[1] || font_pixel[2]) + { + unsigned char *bitmap_pixel = surface->pixels + (y + iy) * surface->pitch + (x + ix) * 3; + + for (unsigned int j = 0; j < 3; ++j) + { + const double alpha = pow((font_pixel[j] / 255.0), 1.0 / 1.8); // Gamma correction + bitmap_pixel[j] = (unsigned char)((colours[j] * alpha) + (bitmap_pixel[j] * (1.0 - alpha))); // Alpha blending + } + } + } + } + + break; + + case FONT_PIXEL_MODE_GRAY: + for (unsigned int iy = MAX(-y, 0); y + iy < MIN(y + glyph->height, surface->height); ++iy) + { + for (unsigned int ix = MAX(-x, 0); x + ix < MIN(x + glyph->width, surface->width); ++ix) + { + const unsigned char font_pixel = glyph->pixels[iy * glyph->pitch + ix]; + + if (font_pixel) + { + const double alpha = pow((double)font_pixel / (glyph->total_greys - 1), 1.0 / 1.8); // Gamma-corrected + + unsigned char *bitmap_pixel = surface->pixels + (y + iy) * surface->pitch + (x + ix) * 3; + + for (unsigned int j = 0; j < 3; ++j) + bitmap_pixel[j] = (unsigned char)((colours[j] * alpha) + (bitmap_pixel[j] * (1.0 - alpha))); // Alpha blending + } + } + } + + break; + + case FONT_PIXEL_MODE_MONO: + for (unsigned int iy = MAX(-y, 0); y + iy < MIN(y + glyph->height, surface->height); ++iy) + { + for (unsigned int ix = MAX(-x, 0); x + ix < MIN(x + glyph->width, surface->width); ++ix) + { + if (glyph->pixels[iy * glyph->pitch + ix]) + { + unsigned char *bitmap_pixel = surface->pixels + (y + iy) * surface->pitch + (x + ix) * 3; + + for (unsigned int j = 0; j < 3; ++j) + bitmap_pixel[j] = colours[j]; + } + } + } + + break; + } +} + +void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) +{ + Backend_DrawGlyph(&framebuffer, glyph, x, y, colours); } void Backend_HandleDeviceLoss(void) diff --git a/src/Draw.cpp b/src/Draw.cpp index 65a01e24..cfa8889e 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -16,12 +16,6 @@ #include "Tags.h" #include "Backends/Rendering.h" -struct SURFACE -{ - BOOL in_use; - Backend_Surface *backend; -}; - SDL_Window *gWindow; static SDL_PixelFormat *rgb24_pixel_format; // Needed because SDL2 is stupid @@ -32,6 +26,12 @@ RECT grcFull = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; int magnification; BOOL fullscreen; +struct SURFACE +{ + BOOL in_use; + Backend_Surface *backend; +}; + SURFACE surf[SURFACE_ID_MAX]; FontObject *gFont; @@ -559,12 +559,12 @@ void InitTextObject(const char *font_name) void PutText(int x, int y, const char *text, unsigned long color) { - Backend_DrawTextToScreen(gFont, x * magnification, y * magnification, text, color); + DrawText(gFont, NULL, x * magnification, y * magnification, color, text, strlen(text)); } void PutText2(int x, int y, const char *text, unsigned long color, Surface_Ids surf_no) { - Backend_DrawText(surf[surf_no].backend, gFont, x * magnification, y * magnification, text, color); + DrawText(gFont, surf[surf_no].backend, x * magnification, y * magnification, color, text, strlen(text)); } void EndTextObject() diff --git a/src/Font.cpp b/src/Font.cpp index d780611f..4487f181 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -12,7 +12,9 @@ #include "WindowsWrapper.h" +#include "Draw.h" #include "File.h" +#include "Backends/Rendering.h" // Cave Story wasn't intended to use font anti-aliasing. It's only because Microsoft enabled it // by default from Windows Vista onwards that the game started using it. @@ -25,19 +27,13 @@ #define DISABLE_FONT_ANTIALIASING #endif -#undef MIN -#undef MAX -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) > (b) ? (a) : (b)) - typedef struct CachedGlyph { unsigned long unicode_value; - FT_Bitmap bitmap; - unsigned char pixel_mode; int x; int y; int x_advance; + Backend_Glyph *backend; struct CachedGlyph *next; } CachedGlyph; @@ -1737,12 +1733,33 @@ static CachedGlyph* GetGlyphCached(FontObject *font_object, unsigned long unicod #endif glyph->unicode_value = unicode_value; - FT_Bitmap_New(&glyph->bitmap); - FT_Bitmap_Convert(font_object->library, &font_object->face->glyph->bitmap, &glyph->bitmap, 1); - glyph->pixel_mode = font_object->face->glyph->bitmap.pixel_mode; glyph->x = font_object->face->glyph->bitmap_left; glyph->y = (FT_MulFix(font_object->face->ascender, font_object->face->size->metrics.y_scale) - font_object->face->glyph->metrics.horiBearingY + (64 / 2)) / 64; glyph->x_advance = font_object->face->glyph->advance.x / 64; + + FT_Bitmap bitmap; + FT_Bitmap_New(&bitmap); + FT_Bitmap_Convert(font_object->library, &font_object->face->glyph->bitmap, &bitmap, 1); + + unsigned char pixel_mode; + switch (font_object->face->glyph->bitmap.pixel_mode) + { + case FT_PIXEL_MODE_LCD: + pixel_mode = FONT_PIXEL_MODE_LCD; + break; + + case FT_PIXEL_MODE_GRAY: + pixel_mode = FONT_PIXEL_MODE_GRAY; + break; + + case FT_PIXEL_MODE_MONO: + pixel_mode = FONT_PIXEL_MODE_MONO; + break; + } + + glyph->backend = Backend_LoadGlyph(bitmap.buffer, bitmap.width, bitmap.rows, bitmap.pitch, bitmap.num_grays, pixel_mode); + + FT_Bitmap_Done(font_object->library, &bitmap); } return glyph; @@ -1755,7 +1772,7 @@ static void UnloadCachedGlyphs(FontObject *font_object) { CachedGlyph *next_glyph = glyph->next; - FT_Bitmap_Done(font_object->library, &glyph->bitmap); + Backend_UnloadGlyph(glyph->backend); free(glyph); glyph = next_glyph; @@ -1838,7 +1855,7 @@ FontObject* LoadFont(const char *font_filename, unsigned int cell_width, unsigne return font_object; } -void DrawText(FontObject *font_object, unsigned char *bitmap_buffer, size_t bitmap_pitch, int bitmap_width, int bitmap_height, int x, int y, unsigned long colour, const char *string, size_t string_length) +void DrawText(FontObject *font_object, Backend_Surface *surface, int x, int y, unsigned long colour, const char *string, size_t string_length) { if (font_object != NULL) { @@ -1866,67 +1883,12 @@ void DrawText(FontObject *font_object, unsigned char *bitmap_buffer, size_t bitm const int letter_x = x + pen_x + glyph->x; const int letter_y = y + glyph->y; - switch (glyph->pixel_mode) + if (glyph->backend) { - case FT_PIXEL_MODE_LCD: - for (int iy = MAX(-letter_y, 0); letter_y + iy < MIN(letter_y + (int)glyph->bitmap.rows, bitmap_height); ++iy) - { - for (int ix = MAX(-letter_x, 0); letter_x + ix < MIN(letter_x + (int)glyph->bitmap.width / 3, bitmap_width); ++ix) - { - const unsigned char *font_pixel = glyph->bitmap.buffer + iy * glyph->bitmap.pitch + ix * 3; - - if (font_pixel[0] || font_pixel[1] || font_pixel[2]) - { - unsigned char *bitmap_pixel = bitmap_buffer + (letter_y + iy) * bitmap_pitch + (letter_x + ix) * 3; - - for (unsigned int j = 0; j < 3; ++j) - { - const double alpha = pow((font_pixel[j] / 255.0), 1.0 / 1.8); // Gamma correction - bitmap_pixel[j] = (unsigned char)((colours[j] * alpha) + (bitmap_pixel[j] * (1.0 - alpha))); // Alpha blending - } - } - } - } - - break; - - case FT_PIXEL_MODE_GRAY: - for (int iy = MAX(-letter_y, 0); letter_y + iy < MIN(letter_y + (int)glyph->bitmap.rows, bitmap_height); ++iy) - { - for (int ix = MAX(-letter_x, 0); letter_x + ix < MIN(letter_x + (int)glyph->bitmap.width, bitmap_width); ++ix) - { - const unsigned char font_pixel = glyph->bitmap.buffer[iy * glyph->bitmap.pitch + ix]; - - if (font_pixel) - { - const double alpha = pow((double)font_pixel / (glyph->bitmap.num_grays - 1), 1.0 / 1.8); // Gamma-corrected - - unsigned char *bitmap_pixel = bitmap_buffer + (letter_y + iy) * bitmap_pitch + (letter_x + ix) * 3; - - for (unsigned int j = 0; j < 3; ++j) - bitmap_pixel[j] = (unsigned char)((colours[j] * alpha) + (bitmap_pixel[j] * (1.0 - alpha))); // Alpha blending - } - } - } - - break; - - case FT_PIXEL_MODE_MONO: - for (int iy = MAX(-letter_y, 0); letter_y + iy < MIN(letter_y + (int)glyph->bitmap.rows, bitmap_height); ++iy) - { - for (int ix = MAX(-letter_x, 0); letter_x + ix < MIN(letter_x + (int)glyph->bitmap.width, bitmap_width); ++ix) - { - if (glyph->bitmap.buffer[iy * glyph->bitmap.pitch + ix]) - { - unsigned char *bitmap_pixel = bitmap_buffer + (letter_y + iy) * bitmap_pitch + (letter_x + ix) * 3; - - for (unsigned int j = 0; j < 3; ++j) - bitmap_pixel[j] = colours[j]; - } - } - } - - break; + if (surface) + Backend_DrawGlyph(surface, glyph->backend, letter_x, letter_y, colours); + else + Backend_DrawGlyphToScreen(glyph->backend, letter_x, letter_y, colours); } pen_x += glyph->x_advance; diff --git a/src/Font.h b/src/Font.h index 75e2e379..2e56ffe7 100644 --- a/src/Font.h +++ b/src/Font.h @@ -2,9 +2,11 @@ #include +#include "Backends/Rendering.h" + 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); -void DrawText(FontObject *font_object, unsigned char *bitmap_buffer, size_t bitmap_pitch, int bitmap_width, int bitmap_height, int x, int y, unsigned long colour, const char *string, size_t string_length); +void DrawText(FontObject *font_object, Backend_Surface *surface, int x, int y, unsigned long colour, const char *string, size_t string_length); void UnloadFont(FontObject *font_object); From 6a7fd148339a91c66a265f4dc374350c31a38eaf Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 23 Jul 2019 17:20:56 +0100 Subject: [PATCH 024/128] Font refactor part 2: SDL_Surface No per-component alpha support here --- src/Backends/Rendering.h | 1 + src/Backends/Rendering/SDLSurface.cpp | 89 +++++++++++++++++++++++++-- src/Backends/Rendering/Software.cpp | 5 ++ src/Font.cpp | 2 +- 4 files changed, 92 insertions(+), 5 deletions(-) diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index 8f2be6e0..b3239995 100644 --- a/src/Backends/Rendering.h +++ b/src/Backends/Rendering.h @@ -26,6 +26,7 @@ void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, lon void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue); void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue); void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect); +BOOL Backend_SupportsSubpixelGlyph(void); Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch, unsigned short total_greys, unsigned char pixel_mode); void Backend_UnloadGlyph(Backend_Glyph *glyph); void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours); diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index c7e173f6..ec530add 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -14,6 +14,11 @@ typedef struct Backend_Surface SDL_Surface *sdl_surface; } Backend_Surface; +typedef struct Backend_Glyph +{ + SDL_Surface *sdl_surface; +} Backend_Glyph; + static SDL_Window *window; static SDL_Surface *window_surface; @@ -132,14 +137,90 @@ void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) Backend_Blit(&framebuffer, rect, surface, rect->left, rect->top, FALSE); } -void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour) +BOOL Backend_SupportsSubpixelGlyph(void) { - DrawText(font, (unsigned char*)surface->sdl_surface->pixels, surface->sdl_surface->pitch, surface->sdl_surface->w, surface->sdl_surface->h, x, y, colour, text, strlen(text)); + return FALSE; // SDL_Surfaces don't have per-component alpha } -void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour) +Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch, unsigned short total_greys, unsigned char pixel_mode) { - Backend_DrawText(&framebuffer, font, x, y, text, colour); + Backend_Glyph *glyph = (Backend_Glyph*)malloc(sizeof(Backend_Glyph)); + + if (glyph == NULL) + return NULL; + + glyph->sdl_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, SDL_PIXELFORMAT_RGBA32); + + if (glyph->sdl_surface == NULL) + { + free(glyph); + return NULL; + } + + switch (pixel_mode) + { + // FONT_PIXEL_MODE_LCD is unsupported + + case FONT_PIXEL_MODE_GRAY: + for (unsigned int y = 0; y < height; ++y) + { + const unsigned char *source_pointer = pixels + y * pitch; + unsigned char *destination_pointer = (unsigned char*)glyph->sdl_surface->pixels + y * glyph->sdl_surface->pitch; + + for (unsigned int x = 0; x < width; ++x) + { + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = (unsigned char)(pow((double)*source_pointer++ / (total_greys - 1), 1.0 / 1.8) * 255.0); + } + } + + break; + + case FONT_PIXEL_MODE_MONO: + for (unsigned int y = 0; y < height; ++y) + { + const unsigned char *source_pointer = pixels + y * pitch; + unsigned char *destination_pointer = (unsigned char*)glyph->sdl_surface->pixels + y * glyph->sdl_surface->pitch; + + for (unsigned int x = 0; x < width; ++x) + { + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = *source_pointer++ ? 0xFF : 0; + } + } + + break; + } + + return glyph; +} + +void Backend_UnloadGlyph(Backend_Glyph *glyph) +{ + SDL_FreeSurface(glyph->sdl_surface); + free(glyph); +} + +void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) +{ + SDL_Rect rect; + rect.x = x; + rect.y = y; + rect.w = glyph->sdl_surface->w; + rect.h = glyph->sdl_surface->h; + + SDL_SetSurfaceColorMod(glyph->sdl_surface, colours[0], colours[1], colours[2]); + + SDL_BlitSurface(glyph->sdl_surface, NULL, surface->sdl_surface, &rect); +} + +void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) +{ + Backend_DrawGlyph(&framebuffer, glyph, x, y, colours); } void Backend_HandleDeviceLoss(void) diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 25c69bfa..7b9bd4f9 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -255,6 +255,11 @@ void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) Backend_Blit(&framebuffer, rect, surface, rect->left, rect->top, FALSE); } +BOOL Backend_SupportsSubpixelGlyph(void) +{ + return TRUE; // It's a software renderer, baby +} + Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch, unsigned short total_greys, unsigned char pixel_mode) { Backend_Glyph *glyph = (Backend_Glyph*)malloc(sizeof(Backend_Glyph)); diff --git a/src/Font.cpp b/src/Font.cpp index 4487f181..64ab31f8 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -1788,7 +1788,7 @@ FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, unsign FT_Init_FreeType(&font_object->library); #ifndef DISABLE_FONT_ANTIALIASING - font_object->lcd_mode = FT_Library_SetLcdFilter(font_object->library, FT_LCD_FILTER_DEFAULT) != FT_Err_Unimplemented_Feature; + font_object->lcd_mode = Backend_SupportsSubpixelGlyph() && FT_Library_SetLcdFilter(font_object->library, FT_LCD_FILTER_DEFAULT) != FT_Err_Unimplemented_Feature; #endif font_object->data = (unsigned char*)malloc(data_size); From e2054918a606d89c47027c37a8b3a6c88d6203f8 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 23 Jul 2019 17:57:32 +0100 Subject: [PATCH 025/128] Font refactor part 3: SDL_Texture Getting kinda messy, having to maintain two different ways of drawing - colour-key and alpha-blending. In the enhanced branch, which uses alpha-blending for everything, these can be merged. I'm noticing a huge delay in shutdown time. There's probably a bug in here. --- src/Backends/Rendering/SDLTexture.cpp | 227 ++++++++++++++++++-------- 1 file changed, 163 insertions(+), 64 deletions(-) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 0c962888..f818658b 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -11,6 +11,7 @@ typedef struct Backend_Surface { + BOOL alpha; BOOL needs_syncing; SDL_Surface *sdl_surface; SDL_Texture *texture; @@ -19,6 +20,11 @@ typedef struct Backend_Surface struct Backend_Surface *prev; } Backend_Surface; +typedef struct Backend_Glyph +{ + Backend_Surface *surface; +} Backend_Glyph; + static SDL_Renderer *renderer; static SDL_Texture *screen_texture; @@ -26,32 +32,79 @@ static Backend_Surface *surface_list_head; static void FlushSurface(Backend_Surface *surface) { - unsigned char *buffer = (unsigned char*)malloc(surface->sdl_surface->w * surface->sdl_surface->h * 4); - unsigned char *buffer_pointer = buffer; - - // Convert the SDL_Surface's colour-keyed pixels to RGBA32 - for (int y = 0; y < surface->sdl_surface->h; ++y) + if (surface->alpha) { - unsigned char *src_pixel = (unsigned char*)surface->sdl_surface->pixels + (y * surface->sdl_surface->pitch); + SDL_UpdateTexture(surface->texture, NULL, surface->sdl_surface->pixels, surface->sdl_surface->pitch); + } + else + { + unsigned char *buffer = (unsigned char*)malloc(surface->sdl_surface->w * surface->sdl_surface->h * 4); + unsigned char *buffer_pointer = buffer; - for (int x = 0; x < surface->sdl_surface->w; ++x) + // Convert the SDL_Surface's colour-keyed pixels to RGBA32 + for (int y = 0; y < surface->sdl_surface->h; ++y) { - *buffer_pointer++ = src_pixel[0]; - *buffer_pointer++ = src_pixel[1]; - *buffer_pointer++ = src_pixel[2]; + unsigned char *src_pixel = (unsigned char*)surface->sdl_surface->pixels + (y * surface->sdl_surface->pitch); - if (src_pixel[0] == 0 && src_pixel[1] == 0 && src_pixel[2] == 0) // Assumes the colour key will always be #000000 (black) - *buffer_pointer++ = 0; - else - *buffer_pointer++ = 0xFF; + for (int x = 0; x < surface->sdl_surface->w; ++x) + { + *buffer_pointer++ = src_pixel[0]; + *buffer_pointer++ = src_pixel[1]; + *buffer_pointer++ = src_pixel[2]; - src_pixel += 3; + if (src_pixel[0] == 0 && src_pixel[1] == 0 && src_pixel[2] == 0) // Assumes the colour key will always be #000000 (black) + *buffer_pointer++ = 0; + else + *buffer_pointer++ = 0xFF; + + src_pixel += 3; + } } + + SDL_UpdateTexture(surface->texture, NULL, buffer, surface->sdl_surface->w * 4); + + free(buffer); + } +} + +Backend_Surface* CreateSurface(unsigned int width, unsigned int height, BOOL alpha) +{ + Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); + + if (surface == NULL) + return NULL; + + surface->sdl_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, alpha ? SDL_PIXELFORMAT_RGBA32 : SDL_PIXELFORMAT_RGB24); + + if (surface->sdl_surface == NULL) + { + free(surface); + return NULL; } - SDL_UpdateTexture(surface->texture, NULL, buffer, surface->sdl_surface->w * 4); + surface->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, width, height); - free(buffer); + if (surface->texture == NULL) + { + SDL_FreeSurface(surface->sdl_surface); + free(surface); + return NULL; + } + + surface->alpha = alpha; + + if (!surface->alpha) + SDL_SetColorKey(surface->sdl_surface, SDL_TRUE, SDL_MapRGB(surface->sdl_surface->format, 0, 0, 0)); + + surface->needs_syncing = FALSE; + + surface->next = surface_list_head; + surface->prev = NULL; + surface_list_head = surface; + if (surface->next) + surface->next->prev = surface; + + return surface; } static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect) @@ -100,39 +153,7 @@ void Backend_DrawScreen(void) Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) { - Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); - - if (surface == NULL) - return NULL; - - surface->sdl_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, SDL_PIXELFORMAT_RGB24); - - if (surface->sdl_surface == NULL) - { - free(surface); - return NULL; - } - - surface->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, width, height); - - if (surface->texture == NULL) - { - SDL_FreeSurface(surface->sdl_surface); - free(surface); - return NULL; - } - - SDL_SetColorKey(surface->sdl_surface, SDL_TRUE, SDL_MapRGB(surface->sdl_surface->format, 0, 0, 0)); - - surface->needs_syncing = FALSE; - - surface->next = surface_list_head; - surface->prev = NULL; - surface_list_head = surface; - if (surface->next) - surface->next->prev = surface; - - return surface; + return CreateSurface(width, height, FALSE); } void Backend_FreeSurface(Backend_Surface *surface) @@ -267,27 +288,105 @@ void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) SDL_SetRenderTarget(renderer, screen_texture); } -void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour) +BOOL Backend_SupportsSubpixelGlyph(void) { - DrawText(font, (unsigned char*)surface->sdl_surface->pixels, surface->sdl_surface->pitch, surface->sdl_surface->w, surface->sdl_surface->h, x, y, colour, text, strlen(text)); - surface->needs_syncing = TRUE; + return FALSE; // SDL_Textures don't have per-component alpha } -void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour) +Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch, unsigned short total_greys, unsigned char pixel_mode) { - // Painfully slow. Really need to add hardware-accelerated font rendering. - int surface_width, surface_height; - SDL_GetRendererOutputSize(renderer, &surface_width, &surface_height); + Backend_Glyph *glyph = (Backend_Glyph*)malloc(sizeof(Backend_Glyph)); - SDL_Surface *screen_surface = SDL_CreateRGBSurfaceWithFormat(0, surface_width, surface_height, 0, SDL_PIXELFORMAT_RGB24); - SDL_RenderReadPixels(renderer, NULL, SDL_PIXELFORMAT_RGB24, screen_surface->pixels, screen_surface->pitch); + if (glyph == NULL) + return NULL; - DrawText(font, (unsigned char*)screen_surface->pixels, screen_surface->pitch, screen_surface->w, screen_surface->h, x, y, colour, text, strlen(text)); + glyph->surface = CreateSurface(width, height, TRUE); - SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, screen_surface); - SDL_FreeSurface(screen_surface); - SDL_RenderCopy(renderer, texture, NULL, NULL); - SDL_DestroyTexture(texture); + if (glyph->surface == NULL) + { + free(glyph); + return NULL; + } + + unsigned int surface_pitch; + unsigned char *surface_pixels = Backend_Lock(glyph->surface, &surface_pitch); + + switch (pixel_mode) + { + // FONT_PIXEL_MODE_LCD is unsupported + + case FONT_PIXEL_MODE_GRAY: + for (unsigned int y = 0; y < height; ++y) + { + const unsigned char *source_pointer = pixels + y * pitch; + unsigned char *destination_pointer = surface_pixels + y * surface_pitch; + + for (unsigned int x = 0; x < width; ++x) + { + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = (unsigned char)(pow((double)*source_pointer++ / (total_greys - 1), 1.0 / 1.8) * 255.0); + } + } + + break; + + case FONT_PIXEL_MODE_MONO: + for (unsigned int y = 0; y < height; ++y) + { + const unsigned char *source_pointer = pixels + y * pitch; + unsigned char *destination_pointer = surface_pixels + y * surface_pitch; + + for (unsigned int x = 0; x < width; ++x) + { + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = *source_pointer++ ? 0xFF : 0; + } + } + + break; + } + + Backend_Unlock(glyph->surface); + + return glyph; +} + +void Backend_UnloadGlyph(Backend_Glyph *glyph) +{ + Backend_FreeSurface(glyph->surface); + free(glyph); +} + +void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) +{ + RECT rect; + rect.left = 0; + rect.top = 0; + rect.right = glyph->surface->sdl_surface->w; + rect.bottom = glyph->surface->sdl_surface->h; + + SDL_SetSurfaceColorMod(glyph->surface->sdl_surface, colours[0], colours[1], colours[2]); + SDL_SetTextureColorMod(glyph->surface->texture, colours[0], colours[1], colours[2]); + + Backend_Blit(glyph->surface, &rect, surface, x, y, TRUE); +} + +void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) +{ + RECT rect; + rect.left = 0; + rect.top = 0; + rect.right = glyph->surface->sdl_surface->w; + rect.bottom = glyph->surface->sdl_surface->h; + + SDL_SetSurfaceColorMod(glyph->surface->sdl_surface, colours[0], colours[1], colours[2]); + SDL_SetTextureColorMod(glyph->surface->texture, colours[0], colours[1], colours[2]); + + Backend_BlitToScreen(glyph->surface, &rect, x, y, TRUE); } void Backend_HandleDeviceLoss(void) From 8aad8a662851860ee6aa157ccaf45283fa261cec Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 23 Jul 2019 20:05:38 +0100 Subject: [PATCH 026/128] Font refactor part 4: Thy Flesh Co- I mean, OpenGL Hard mode. Wound up debugging a weird issue for about half an hour. Turns out you don't need to reset the matrix when you switch framebuffer target? I don't really know how that works. Anyway, yay font rendering is in the OpenGL backend now. --- src/Backends/Rendering/OpenGL2.cpp | 137 +++++++++++++++++++++++------ 1 file changed, 112 insertions(+), 25 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index c77688be..49439f6f 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -18,6 +18,13 @@ typedef struct Backend_Surface unsigned char *pixels; } Backend_Surface; +typedef struct Backend_Glyph +{ + GLuint texture_id; + unsigned int width; + unsigned int height; +} Backend_Glyph; + static SDL_Window *window; static SDL_GLContext context; static GLuint colour_key_program_id; @@ -88,6 +95,8 @@ BOOL Backend_Init(SDL_Window *p_window) // glLoadIdentity(); glEnable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); @@ -228,14 +237,7 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur // Point our framebuffer to the destination texture glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, destination_surface->texture_id, 0); - // The matrix needs resetting to fit the dimensions of the destination texture - glPushMatrix(); - glLoadIdentity(); - glOrtho(0.0, destination_surface->width, 0.0, destination_surface->height, 1.0, -1.0); - BlitCommon(source_surface, rect, x, y, colour_key); - - glPopMatrix(); } void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) @@ -268,14 +270,7 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha // Point our framebuffer to the destination texture glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); - // The matrix needs resetting to fit the dimensions of the destination texture - glPushMatrix(); - glLoadIdentity(); - glOrtho(0.0, surface->width, 0.0, surface->height, 1.0, -1.0); - ColourFillCommon(rect, red, green, blue); - - glPopMatrix(); } void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) @@ -291,24 +286,116 @@ void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) // Point our framebuffer to the destination texture glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); - // The matrix needs resetting to fit the dimensions of the destination texture - glPushMatrix(); - glLoadIdentity(); - glOrtho(0.0, surface->width, 0.0, surface->height, 1.0, -1.0); - BlitCommon(&framebuffer_surface, rect, rect->left, rect->top, FALSE); - - glPopMatrix(); } -void Backend_DrawText(Backend_Surface *surface, FontObject *font, int x, int y, const char *text, unsigned long colour) +BOOL Backend_SupportsSubpixelGlyph(void) { - // Soon + return FALSE; // Per-component alpha is available as an extension, but I haven't looked into it yet } -void Backend_DrawTextToScreen(FontObject *font, int x, int y, const char *text, unsigned long colour) +Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch, unsigned short total_greys, unsigned char pixel_mode) { - // Soon + Backend_Glyph *glyph = (Backend_Glyph*)malloc(sizeof(Backend_Glyph)); + + if (glyph == NULL) + return NULL; + + unsigned char *buffer = (unsigned char*)malloc(width * height * 4); + + switch (pixel_mode) + { + // FONT_PIXEL_MODE_LCD is unsupported + + case FONT_PIXEL_MODE_GRAY: + for (unsigned int y = 0; y < height; ++y) + { + const unsigned char *source_pointer = pixels + y * pitch; + unsigned char *destination_pointer = buffer + y * width * 4; + + for (unsigned int x = 0; x < width; ++x) + { + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = (unsigned char)(pow((double)*source_pointer++ / (total_greys - 1), 1.0 / 1.8) * 255.0); + } + } + + break; + + case FONT_PIXEL_MODE_MONO: + for (unsigned int y = 0; y < height; ++y) + { + const unsigned char *source_pointer = pixels + y * pitch; + unsigned char *destination_pointer = buffer + y * width * 4; + + for (unsigned int x = 0; x < width; ++x) + { + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = 0xFF; + *destination_pointer++ = *source_pointer++ ? 0xFF : 0; + } + } + + break; + } + + glGenTextures(1, &glyph->texture_id); + glBindTexture(GL_TEXTURE_2D, glyph->texture_id); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glyph->width = width; + glyph->height = height; + + free(buffer); + + return glyph; +} + +void Backend_UnloadGlyph(Backend_Glyph *glyph) +{ + glDeleteTextures(1, &glyph->texture_id); + free(glyph); +} + +static void DrawGlyphCommon(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) +{ + // Disable colour-keying + glUseProgram(0); + + glBindTexture(GL_TEXTURE_2D, glyph->texture_id); + + glBegin(GL_QUADS); + glColor3f(colours[0] / 255.0f, colours[1] / 255.0f, colours[2] / 255.0f); + glTexCoord2f(0.0f, 0.0f); + glVertex2f((GLfloat)x, (GLfloat)y); + glTexCoord2f(1.0f, 0.0f); + glVertex2f((GLfloat)x + glyph->width, (GLfloat)y); + glTexCoord2f(1.0f, 1.0f); + glVertex2f((GLfloat)x + glyph->width, (GLfloat)y + glyph->height); + glTexCoord2f(0.0f, 1.0f); + glVertex2f((GLfloat)x, (GLfloat)y + glyph->height); + glEnd(); +} + +void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) +{ + // Point our framebuffer to the destination texture + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + + DrawGlyphCommon(glyph, x, y, colours); +} + +void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) +{ + // Point our framebuffer to the screen texture + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + + DrawGlyphCommon(glyph, x, y, colours); } void Backend_HandleDeviceLoss(void) From d3129bc4bc6515b48eb1705d43bb07fa3ebdebcb Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 23 Jul 2019 21:46:57 +0100 Subject: [PATCH 027/128] Font refactor part 5: Sigil (optimised software renderer) --- src/Backends/Rendering/Software.cpp | 99 +++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 19 deletions(-) diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 7b9bd4f9..b159b43d 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -22,11 +22,9 @@ typedef struct Backend_Surface typedef struct Backend_Glyph { - unsigned char *pixels; + void *pixels; unsigned int width; unsigned int height; - int pitch; - unsigned short total_greys; unsigned char pixel_mode; } Backend_Glyph; @@ -267,20 +265,85 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width if (glyph == NULL) return NULL; - glyph->pixels = (unsigned char*)malloc(pitch * height); - - if (glyph->pixels == NULL) + switch (pixel_mode) { - free(glyph); - return NULL; - } + case FONT_PIXEL_MODE_LCD: + { + glyph->pixels = malloc(width * height * sizeof(double) * 3); - memcpy(glyph->pixels, pixels, pitch * height); + if (glyph->pixels == NULL) + { + free(glyph); + return NULL; + } + + double *destination_pointer = (double*)glyph->pixels; + + for (unsigned int y = 0; y < height; ++y) + { + const unsigned char *source_pointer = pixels + y * pitch; + + for (unsigned int x = 0; x < width; ++x) + { + for (unsigned int i = 0; i < 3; ++i) + { + *destination_pointer++ = pow((*source_pointer++ / 255.0), 1.0 / 1.8); // Gamma correction + } + } + } + + break; + } + + case FONT_PIXEL_MODE_GRAY: + { + glyph->pixels = malloc(width * height * sizeof(double)); + + if (glyph->pixels == NULL) + { + free(glyph); + return NULL; + } + + double *destination_pointer = (double*)glyph->pixels; + + for (unsigned int y = 0; y < height; ++y) + { + const unsigned char *source_pointer = pixels + y * pitch; + + for (unsigned int x = 0; x < width; ++x) + { + *destination_pointer++ = pow((double)*source_pointer++ / (total_greys - 1), 1.0 / 1.8); // Gamma correction + } + } + + break; + } + + case FONT_PIXEL_MODE_MONO: + { + glyph->pixels = malloc(width * height); + + if (glyph->pixels == NULL) + { + free(glyph); + return NULL; + } + + for (unsigned int y = 0; y < height; ++y) + { + const unsigned char *source_pointer = pixels + y * pitch; + unsigned char *destination_pointer = (unsigned char*)glyph->pixels + y * width; + + memcpy(destination_pointer, source_pointer, width); + } + + break; + } + } glyph->width = width; glyph->height = height; - glyph->pitch = pitch; - glyph->total_greys = total_greys; glyph->pixel_mode = pixel_mode; return glyph; @@ -301,7 +364,7 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l { for (unsigned int ix = MAX(-x, 0); x + ix < MIN(x + glyph->width / 3, surface->width); ++ix) { - const unsigned char *font_pixel = glyph->pixels + iy * glyph->pitch + ix * 3; + const double *font_pixel = (double*)glyph->pixels + (iy * glyph->width + ix) * 3; if (font_pixel[0] || font_pixel[1] || font_pixel[2]) { @@ -309,7 +372,7 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l for (unsigned int j = 0; j < 3; ++j) { - const double alpha = pow((font_pixel[j] / 255.0), 1.0 / 1.8); // Gamma correction + const double alpha = font_pixel[j]; bitmap_pixel[j] = (unsigned char)((colours[j] * alpha) + (bitmap_pixel[j] * (1.0 - alpha))); // Alpha blending } } @@ -323,12 +386,10 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l { for (unsigned int ix = MAX(-x, 0); x + ix < MIN(x + glyph->width, surface->width); ++ix) { - const unsigned char font_pixel = glyph->pixels[iy * glyph->pitch + ix]; + const double alpha = ((double*)glyph->pixels)[iy * glyph->width + ix]; - if (font_pixel) + if (alpha) { - const double alpha = pow((double)font_pixel / (glyph->total_greys - 1), 1.0 / 1.8); // Gamma-corrected - unsigned char *bitmap_pixel = surface->pixels + (y + iy) * surface->pitch + (x + ix) * 3; for (unsigned int j = 0; j < 3; ++j) @@ -344,7 +405,7 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l { for (unsigned int ix = MAX(-x, 0); x + ix < MIN(x + glyph->width, surface->width); ++ix) { - if (glyph->pixels[iy * glyph->pitch + ix]) + if (((unsigned char*)glyph->pixels)[iy * glyph->width + ix]) { unsigned char *bitmap_pixel = surface->pixels + (y + iy) * surface->pitch + (x + ix) * 3; From e17048584954dc45bd938355da04f9aa3a3c10db Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 23 Jul 2019 23:11:24 +0100 Subject: [PATCH 028/128] Document a "bug" in the SDL_Texture backend --- src/Backends/Rendering/SDLTexture.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index f818658b..64f2d2f0 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -363,6 +363,11 @@ void Backend_UnloadGlyph(Backend_Glyph *glyph) void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { + // This is actually slightly imperfect: the SDL_Texture side of things uses alpha, not a colour-key, + // so the bug where the font is blended with the colour key doesn't occur. SDL_Textures don't support + // colour-keys, so the next best thing is relying on the software fallback, but I don't like the idea + // of uploading textures to the GPU every time a glyph is drawn. + RECT rect; rect.left = 0; rect.top = 0; From 0ce05e18376f6431a782229d64120ddf7990514f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 23 Jul 2019 23:13:57 +0100 Subject: [PATCH 029/128] Move a function --- src/Backends/Rendering/SDLTexture.cpp | 80 +++++++++++++-------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 64f2d2f0..748eedf2 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -67,46 +67,6 @@ static void FlushSurface(Backend_Surface *surface) } } -Backend_Surface* CreateSurface(unsigned int width, unsigned int height, BOOL alpha) -{ - Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); - - if (surface == NULL) - return NULL; - - surface->sdl_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, alpha ? SDL_PIXELFORMAT_RGBA32 : SDL_PIXELFORMAT_RGB24); - - if (surface->sdl_surface == NULL) - { - free(surface); - return NULL; - } - - surface->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, width, height); - - if (surface->texture == NULL) - { - SDL_FreeSurface(surface->sdl_surface); - free(surface); - return NULL; - } - - surface->alpha = alpha; - - if (!surface->alpha) - SDL_SetColorKey(surface->sdl_surface, SDL_TRUE, SDL_MapRGB(surface->sdl_surface->format, 0, 0, 0)); - - surface->needs_syncing = FALSE; - - surface->next = surface_list_head; - surface->prev = NULL; - surface_list_head = surface; - if (surface->next) - surface->next->prev = surface; - - return surface; -} - static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect) { sdl_rect->x = (int)rect->left; @@ -151,6 +111,46 @@ void Backend_DrawScreen(void) SDL_RenderPresent(renderer); } +static Backend_Surface* CreateSurface(unsigned int width, unsigned int height, BOOL alpha) +{ + Backend_Surface *surface = (Backend_Surface*)malloc(sizeof(Backend_Surface)); + + if (surface == NULL) + return NULL; + + surface->sdl_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, alpha ? SDL_PIXELFORMAT_RGBA32 : SDL_PIXELFORMAT_RGB24); + + if (surface->sdl_surface == NULL) + { + free(surface); + return NULL; + } + + surface->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, width, height); + + if (surface->texture == NULL) + { + SDL_FreeSurface(surface->sdl_surface); + free(surface); + return NULL; + } + + surface->alpha = alpha; + + if (!surface->alpha) + SDL_SetColorKey(surface->sdl_surface, SDL_TRUE, SDL_MapRGB(surface->sdl_surface->format, 0, 0, 0)); + + surface->needs_syncing = FALSE; + + surface->next = surface_list_head; + surface->prev = NULL; + surface_list_head = surface; + if (surface->next) + surface->next->prev = surface; + + return surface; +} + Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) { return CreateSurface(width, height, FALSE); From b2244f17fc6257caa99f835538bd550a3272c71a Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 23 Jul 2019 23:15:44 +0100 Subject: [PATCH 030/128] Dumb indent --- src/Backends/Rendering/OpenGL2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 49439f6f..9aa66909 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -266,7 +266,7 @@ static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char } void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) -{ +{ // Point our framebuffer to the destination texture glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); From 7bbc0321cd8680ff911b0bd9346516585b505f2f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 24 Jul 2019 20:00:23 +0100 Subject: [PATCH 031/128] Backport OpenGL2 fixes from the enhanced branch --- src/Backends/Rendering/OpenGL2.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 9aa66909..4fbd3f69 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -113,6 +113,7 @@ BOOL Backend_Init(SDL_Window *p_window) // Set up framebuffer (used for surface-to-surface blitting) glGenFramebuffersEXT(1, &framebuffer_id); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_id); // Set up framebuffer screen texture (used for screen-to-surface blitting) glGenTextures(1, &framebuffer_surface.texture_id); @@ -214,6 +215,9 @@ void Backend_Unlock(Backend_Surface *surface) static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) { + if (rect->right - rect->left < 0 || rect->bottom - rect->top < 0) + return; + // Switch to colour-key shader if we have to glUseProgram(colour_key ? colour_key_program_id : 0); @@ -250,6 +254,9 @@ void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, lon static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { + if (rect->right - rect->left < 0 || rect->bottom - rect->top < 0) + return; + // Disable colour-keying glUseProgram(0); @@ -303,6 +310,12 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width unsigned char *buffer = (unsigned char*)malloc(width * height * 4); + if (buffer == NULL) + { + free(glyph); + return NULL; + } + switch (pixel_mode) { // FONT_PIXEL_MODE_LCD is unsupported From b998719ff1207615b0aca74e76bab2e01ec4ff70 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 24 Jul 2019 20:09:27 +0100 Subject: [PATCH 032/128] Update CMakeLists.txt, the Makefile, and the readme --- CMakeLists.txt | 11 +++++------ Makefile | 11 ++++++++++- README.md | 2 ++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cb934a5..ba0f7720 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ option(JAPANESE "Enable the Japanese-language build" OFF) option(FIX_BUGS "Fix certain bugs (see src/Bug Fixes.txt)" OFF) option(NONPORTABLE "Enable bits of code that aren't portable, but are what the original game used" OFF) option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF) -set(RENDERER "Texture" CACHE STRING "Which renderer the game should use: 'Texture' for SDL2's hardware-accelerated Texture API, 'Surface' for SDL2's software-rendered Surface API, and 'Software' for a handwritten software renderer") +set(RENDERER "Texture" CACHE STRING "Which renderer the game should use: 'OpenGL2' for an OpenGL 2.1 renderer, 'Texture' for SDL2's hardware-accelerated Texture API, 'Surface' for SDL2's software-rendered Surface API, and 'Software' for a handwritten software renderer") project(CSE2 LANGUAGES C CXX) @@ -248,6 +248,10 @@ endif() if(RENDERER MATCHES "OpenGL2") target_sources(CSE2 PRIVATE "src/Backends/Rendering/OpenGL2.cpp") + find_package(GLEW REQUIRED) + target_link_libraries(CSE2 GLEW::GLEW) + find_package(OpenGL REQUIRED) + target_link_libraries(CSE2 OpenGL::GL OpenGL::GLU) elseif(RENDERER MATCHES "Texture") target_sources(CSE2 PRIVATE "src/Backends/Rendering/SDLTexture.cpp") elseif(RENDERER MATCHES "Surface") @@ -404,11 +408,6 @@ else() target_link_libraries(CSE2 freetype) endif() -find_package(GLEW REQUIRED) -target_link_libraries(CSE2 GLEW::GLEW) -find_package(OpenGL REQUIRED) -target_link_libraries(CSE2 OpenGL::GL OpenGL::GLU) - ## # DoConfig diff --git a/Makefile b/Makefile index c13e163d..0b74b148 100644 --- a/Makefile +++ b/Makefile @@ -208,7 +208,16 @@ ifneq ($(WINDOWS), 1) RESOURCES += ICON/ICON_MINI.bmp endif -ifeq ($(RENDERER), Texture) +ifeq ($(RENDERER), OpenGL2) + SOURCES += Backends/Rendering/OpenGL2 + CXXFLAGS += `pkg-config glew --cflags` + + ifeq ($(STATIC), 1) + LIBS += `pkg-config glew --libs --static` + else + LIBS += `pkg-config glew --libs` + endif +else ifeq ($(RENDERER), Texture) SOURCES += Backends/Rendering/SDLTexture else ifeq ($(RENDERER), Surface) SOURCES += Backends/Rendering/Software diff --git a/README.md b/README.md index a273e032..eaa19031 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ You can also add the following flags: * `-DFIX_BUGS=ON` - Fix bugs in the game (see [src/Bug Fixes.txt](src/Bug%20Fixes.txt)) * `-DNONPORTABLE=ON` - Enable bits of code that aren't portable, but are what the original game used * `-DFORCE_LOCAL_LIBS=ON` - Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones +* `-DRENDERER=OpenGL2` - Use the hardware-accelerated OpenGL 2.1 renderer * `-DRENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default) * `-DRENDERER=Surface` - Use the software-rendered SDL2 Surface API renderer * `-DRENDERER=Software` - Use a handwritten software renderer @@ -56,6 +57,7 @@ Run 'make' in this folder, preferably with some of the following settings: * `WINDOWS=1` - Enable Windows-only features like a unique file/taskbar icon, and system font loading (needed for the font setting in Config.dat to do anything) * `RASPBERRY_PI=1` - Enable tweaks to improve performance on Raspberry Pis * `NONPORTABLE=1` - Enable bits of code that aren't portable, but are what the original game used +* `RENDERER=OpenGL2` - Use the hardware-accelerated OpenGL 2.1 renderer * `RENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default) * `RENDERER=Surface` - Use the software-rendered SDL2 Surface API renderer * `RENDERER=Software` - Use a hand-written software renderer From 9948fa8b074e16e382fae89e958b186602d5cd7b Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 24 Jul 2019 20:20:06 +0100 Subject: [PATCH 033/128] Move the SDL_Window creation to the rendering backends Whoops, didn't mean to commit the Main.cpp edit way back when I made the OpenGL 2.1 backend. --- src/Backends/Rendering.h | 1 + src/Backends/Rendering/OpenGL2.cpp | 9 +++++++++ src/Backends/Rendering/SDLSurface.cpp | 5 +++++ src/Backends/Rendering/SDLTexture.cpp | 5 +++++ src/Backends/Rendering/Software.cpp | 5 +++++ src/Draw.cpp | 5 +++++ src/Draw.h | 3 +++ src/Main.cpp | 8 ++------ src/WindowsWrapper.h | 1 + 9 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index b3239995..ece37db2 100644 --- a/src/Backends/Rendering.h +++ b/src/Backends/Rendering.h @@ -14,6 +14,7 @@ enum typedef struct Backend_Surface Backend_Surface; typedef struct Backend_Glyph Backend_Glyph; +SDL_Window* Backend_CreateWindow(const char *title, int width, int height); BOOL Backend_Init(SDL_Window *window); void Backend_Deinit(void); void Backend_DrawScreen(void); diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 4fbd3f69..60a0c9fb 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -71,6 +71,15 @@ static GLuint CompileShader(const char *fragment_shader_source) return program_id; } +SDL_Window* Backend_CreateWindow(const char *title, int width, int height) +{ + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + + return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); +} + BOOL Backend_Init(SDL_Window *p_window) { window = p_window; diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index ec530add..7b0c870e 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -38,6 +38,11 @@ static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect) sdl_rect->h = 0; } +SDL_Window* Backend_CreateWindow(const char *title, int width, int height) +{ + return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, 0); +} + BOOL Backend_Init(SDL_Window *p_window) { window = p_window; diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 748eedf2..de888519 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -81,6 +81,11 @@ static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect) sdl_rect->h = 0; } +SDL_Window* Backend_CreateWindow(const char *title, int width, int height) +{ + return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, 0); +} + BOOL Backend_Init(SDL_Window *window) { renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index b159b43d..9ccd5106 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -34,6 +34,11 @@ static SDL_Surface *screen_surface; static Backend_Surface framebuffer; +SDL_Window* Backend_CreateWindow(const char *title, int width, int height) +{ + return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, 0); +} + BOOL Backend_Init(SDL_Window *p_window) { window = p_window; diff --git a/src/Draw.cpp b/src/Draw.cpp index cfa8889e..23913f3c 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -69,6 +69,11 @@ BOOL Flip_SystemTask(HWND hWnd) return TRUE; } +SDL_Window* CreateWindow(const char *title, int width, int height) +{ + return Backend_CreateWindow(title, width, height); +} + BOOL StartDirectDraw(int lMagnification, int lColourDepth) { (void)lColourDepth; // There's no way I'm supporting a bunch of different colour depths diff --git a/src/Draw.h b/src/Draw.h index e7e537b8..c7791462 100644 --- a/src/Draw.h +++ b/src/Draw.h @@ -1,5 +1,7 @@ #pragma once +#include "SDL.h" + #include "WindowsWrapper.h" #ifndef RGB @@ -53,6 +55,7 @@ struct SURFACE; extern SURFACE surf[SURFACE_ID_MAX]; BOOL Flip_SystemTask(HWND hWnd); +SDL_Window* CreateWindow(const char *title, int width, int height); BOOL StartDirectDraw(int lMagnification, int lColourDepth); void EndDirectDraw(); void ReleaseSurface(int s); diff --git a/src/Main.cpp b/src/Main.cpp index 9d8fb8f4..b2e3f82f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -256,12 +256,8 @@ int main(int argc, char *argv[]) windowHeight = WINDOW_HEIGHT * 2; } - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); - // Create window - gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, SDL_WINDOW_OPENGL); + gWindow = CreateWindow(lpWindowName, windowWidth, windowHeight); if (gWindow) { @@ -281,7 +277,7 @@ int main(int argc, char *argv[]) windowHeight = WINDOW_HEIGHT * 2; // Create window - gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0); + gWindow = CreateWindow(lpWindowName, windowWidth, windowHeight); if (gWindow) { diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h index ca0d6229..cbac5af0 100644 --- a/src/WindowsWrapper.h +++ b/src/WindowsWrapper.h @@ -5,6 +5,7 @@ // Avoid name collisions #undef DrawText #undef FindResource +#undef CreateWindow #else typedef int HWND; From d6888040a2db4065a2550c147f754258e8ac0a5c Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 24 Jul 2019 22:08:37 +0100 Subject: [PATCH 034/128] Backport some OpenGL 2.1 fixes --- src/Backends/Rendering/OpenGL2.cpp | 45 ++++++++++++++++++------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 60a0c9fb..ff764b92 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -71,6 +71,16 @@ static GLuint CompileShader(const char *fragment_shader_source) return program_id; } +static void SetRenderTarget(Backend_Surface *surface) +{ + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + + glViewport(0, 0, surface->width, surface->height); + + glLoadIdentity(); + glOrtho(0.0, surface->width, 0.0, surface->height, 1.0, -1.0); +} + SDL_Window* Backend_CreateWindow(const char *title, int width, int height) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); @@ -84,8 +94,8 @@ BOOL Backend_Init(SDL_Window *p_window) { window = p_window; - int screen_width, screen_height; - SDL_GetWindowSize(window, &screen_width, &screen_height); + int window_width, window_height; + SDL_GetWindowSize(window, &window_width, &window_height); context = SDL_GL_CreateContext(window); @@ -96,12 +106,6 @@ BOOL Backend_Init(SDL_Window *p_window) if (!GLEW_EXT_framebuffer_object) return FALSE; -// glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glOrtho(0.0, screen_width, 0.0, screen_height, 1.0, -1.0); - -// glMatrixMode(GL_PROJECTION); -// glLoadIdentity(); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); @@ -127,12 +131,12 @@ BOOL Backend_Init(SDL_Window *p_window) // Set up framebuffer screen texture (used for screen-to-surface blitting) glGenTextures(1, &framebuffer_surface.texture_id); glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screen_width, screen_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, window_width, window_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - framebuffer_surface.width = screen_width; - framebuffer_surface.height = screen_height; + framebuffer_surface.width = window_width; + framebuffer_surface.height = window_height; return TRUE; } @@ -153,6 +157,11 @@ void Backend_DrawScreen(void) // Target actual screen, and not our framebuffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); + + glLoadIdentity(); + glOrtho(0.0, framebuffer_surface.width, 0.0, framebuffer_surface.height, 1.0, -1.0); + // Draw framebuffer to screen glPushMatrix(); glLoadIdentity(); @@ -248,7 +257,7 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) { // Point our framebuffer to the destination texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, destination_surface->texture_id, 0); + SetRenderTarget(destination_surface); BlitCommon(source_surface, rect, x, y, colour_key); } @@ -256,7 +265,7 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) { // Point our framebuffer to the screen texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + SetRenderTarget(&framebuffer_surface); BlitCommon(source_surface, rect, x, y, colour_key); } @@ -284,7 +293,7 @@ static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { // Point our framebuffer to the destination texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + SetRenderTarget(surface); ColourFillCommon(rect, red, green, blue); } @@ -292,7 +301,7 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { // Point our framebuffer to the screen texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + SetRenderTarget(&framebuffer_surface); ColourFillCommon(rect, red, green, blue); } @@ -300,7 +309,7 @@ void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned ch void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) { // Point our framebuffer to the destination texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + SetRenderTarget(surface); BlitCommon(&framebuffer_surface, rect, rect->left, rect->top, FALSE); } @@ -407,7 +416,7 @@ static void DrawGlyphCommon(Backend_Glyph *glyph, long x, long y, const unsigned void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { // Point our framebuffer to the destination texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + SetRenderTarget(surface); DrawGlyphCommon(glyph, x, y, colours); } @@ -415,7 +424,7 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { // Point our framebuffer to the screen texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + SetRenderTarget(&framebuffer_surface); DrawGlyphCommon(glyph, x, y, colours); } From 679c6d0391d2ad520f5c672fa5b25a63518af017 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 24 Jul 2019 22:21:39 +0100 Subject: [PATCH 035/128] More efficient OpenGL font loading --- src/Backends/Rendering/OpenGL2.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index ff764b92..2e6f9a84 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -326,7 +326,9 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width if (glyph == NULL) return NULL; - unsigned char *buffer = (unsigned char*)malloc(width * height * 4); + const int destination_pitch = (width + 3) & ~3; // Round up to the nearest 4 (OpenGL needs this) + + unsigned char *buffer = (unsigned char*)malloc(destination_pitch * height); if (buffer == NULL) { @@ -342,13 +344,10 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width for (unsigned int y = 0; y < height; ++y) { const unsigned char *source_pointer = pixels + y * pitch; - unsigned char *destination_pointer = buffer + y * width * 4; + unsigned char *destination_pointer = buffer + y * destination_pitch; for (unsigned int x = 0; x < width; ++x) { - *destination_pointer++ = 0xFF; - *destination_pointer++ = 0xFF; - *destination_pointer++ = 0xFF; *destination_pointer++ = (unsigned char)(pow((double)*source_pointer++ / (total_greys - 1), 1.0 / 1.8) * 255.0); } } @@ -359,13 +358,10 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width for (unsigned int y = 0; y < height; ++y) { const unsigned char *source_pointer = pixels + y * pitch; - unsigned char *destination_pointer = buffer + y * width * 4; + unsigned char *destination_pointer = buffer + y * destination_pitch; for (unsigned int x = 0; x < width; ++x) { - *destination_pointer++ = 0xFF; - *destination_pointer++ = 0xFF; - *destination_pointer++ = 0xFF; *destination_pointer++ = *source_pointer++ ? 0xFF : 0; } } @@ -375,7 +371,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width glGenTextures(1, &glyph->texture_id); glBindTexture(GL_TEXTURE_2D, glyph->texture_id); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); From 145864cf2dc4dafdf9d7f345a635376bb6f42605 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 24 Jul 2019 23:34:16 +0100 Subject: [PATCH 036/128] Added sanity checks to the backends This fixes the Texture backend bug that made the program take forever to shut down: The problem was that the font system would try to load a glyph that's 0 pixels wide/tall (likely the space character), which SDL2 didn't like, so it would fail to allocate the texture, causing Backend_CreateSurface, and by extension Backend_CreateGlyph, to return a NULL. Later, upon shutdown, the font system would pass this NULL to Backend_FreeGlyph, causing NULL pointer dereferences that make the program take forever to shut down. Personally, I think passing NULLs to the backend is valid behaviour, so I've added a bunch of sanity checks to make sure they're never dereferenced. --- src/Backends/Rendering/OpenGL2.cpp | 30 ++++++++++++++++++++++++++ src/Backends/Rendering/SDLSurface.cpp | 18 ++++++++++++++++ src/Backends/Rendering/SDLTexture.cpp | 31 +++++++++++++++++++++++++++ src/Backends/Rendering/Software.cpp | 18 ++++++++++++++++ 4 files changed, 97 insertions(+) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 2e6f9a84..0fc5a495 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -213,12 +213,18 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) void Backend_FreeSurface(Backend_Surface *surface) { + if (surface == NULL) + return; + glDeleteTextures(1, &surface->texture_id); free(surface); } unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch) { + if (surface == NULL) + return NULL; + surface->pixels = (unsigned char*)malloc(surface->width * surface->height * 3); *pitch = surface->width * 3; return surface->pixels; @@ -226,6 +232,9 @@ unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch) void Backend_Unlock(Backend_Surface *surface) { + if (surface == NULL) + return; + glBindTexture(GL_TEXTURE_2D, surface->texture_id); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, surface->width, surface->height, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels); free(surface->pixels); @@ -256,6 +265,9 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) { + if (source_surface == NULL || destination_surface == NULL) + return; + // Point our framebuffer to the destination texture SetRenderTarget(destination_surface); @@ -264,6 +276,9 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) { + if (source_surface == NULL) + return; + // Point our framebuffer to the screen texture SetRenderTarget(&framebuffer_surface); @@ -292,6 +307,9 @@ static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { + if (surface == NULL) + return; + // Point our framebuffer to the destination texture SetRenderTarget(surface); @@ -308,6 +326,9 @@ void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned ch void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) { + if (surface == NULL) + return; + // Point our framebuffer to the destination texture SetRenderTarget(surface); @@ -385,6 +406,9 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width void Backend_UnloadGlyph(Backend_Glyph *glyph) { + if (glyph == NULL) + return; + glDeleteTextures(1, &glyph->texture_id); free(glyph); } @@ -411,6 +435,9 @@ static void DrawGlyphCommon(Backend_Glyph *glyph, long x, long y, const unsigned void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { + if (glyph == NULL || surface == NULL) + return; + // Point our framebuffer to the destination texture SetRenderTarget(surface); @@ -419,6 +446,9 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { + if (glyph == NULL) + return; + // Point our framebuffer to the screen texture SetRenderTarget(&framebuffer_surface); diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 7b0c870e..56a4cc85 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -88,12 +88,18 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) void Backend_FreeSurface(Backend_Surface *surface) { + if (surface == NULL) + return; + SDL_FreeSurface(surface->sdl_surface); free(surface); } unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch) { + if (surface == NULL) + return NULL; + *pitch = surface->sdl_surface->pitch; return (unsigned char*)surface->sdl_surface->pixels; } @@ -105,6 +111,9 @@ 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) { + if (source_surface == NULL || destination_surface == NULL) + return; + SDL_Rect source_rect; RectToSDLRect(rect, &source_rect); @@ -126,6 +135,9 @@ void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, lon void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { + if (surface == NULL) + return; + SDL_Rect destination_rect; RectToSDLRect(rect, &destination_rect); @@ -206,12 +218,18 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width void Backend_UnloadGlyph(Backend_Glyph *glyph) { + if (glyph == NULL) + return; + SDL_FreeSurface(glyph->sdl_surface); free(glyph); } void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { + if (glyph == NULL || surface == NULL) + return; + SDL_Rect rect; rect.x = x; rect.y = y; diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index de888519..604faaa6 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -163,28 +163,41 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) void Backend_FreeSurface(Backend_Surface *surface) { + if (surface == NULL) + return; + if (surface->next) surface->next->prev = surface->prev; if (surface->prev) surface->prev->next = surface->next; + SDL_DestroyTexture(surface->texture); SDL_FreeSurface(surface->sdl_surface); free(surface); } unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch) { + if (surface == NULL) + return NULL; + *pitch = surface->sdl_surface->pitch; return (unsigned char*)surface->sdl_surface->pixels; } void Backend_Unlock(Backend_Surface *surface) { + if (surface == NULL) + return; + surface->needs_syncing = TRUE; } void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) { + if (source_surface == NULL || destination_surface == NULL) + return; + if (source_surface->needs_syncing) { FlushSurface(source_surface); @@ -209,6 +222,9 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) { + if (source_surface == NULL) + return; + if (source_surface->needs_syncing) { FlushSurface(source_surface); @@ -227,6 +243,9 @@ void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, lon void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { + if (surface == NULL) + return; + SDL_Rect sdl_rect; RectToSDLRect(rect, &sdl_rect); @@ -261,6 +280,9 @@ void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned ch void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) { + if (surface == NULL) + return; + SDL_Rect sdl_rect; RectToSDLRect(rect, &sdl_rect); @@ -362,6 +384,9 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width void Backend_UnloadGlyph(Backend_Glyph *glyph) { + if (glyph == NULL) + return; + Backend_FreeSurface(glyph->surface); free(glyph); } @@ -373,6 +398,9 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l // colour-keys, so the next best thing is relying on the software fallback, but I don't like the idea // of uploading textures to the GPU every time a glyph is drawn. + if (glyph == NULL || surface == NULL) + return; + RECT rect; rect.left = 0; rect.top = 0; @@ -387,6 +415,9 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { + if (glyph == NULL) + return; + RECT rect; rect.left = 0; rect.top = 0; diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 9ccd5106..0f88e668 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -93,12 +93,18 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) void Backend_FreeSurface(Backend_Surface *surface) { + if (surface == NULL) + return; + free(surface->pixels); free(surface); } unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch) { + if (surface == NULL) + return NULL; + *pitch = surface->pitch; return surface->pixels; } @@ -110,6 +116,9 @@ 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) { + if (source_surface == NULL || destination_surface == NULL) + return; + RECT rect_clamped; rect_clamped.left = rect->left; @@ -195,6 +204,9 @@ void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, lon void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { + if (surface == NULL) + return; + RECT rect_clamped; rect_clamped.left = rect->left; @@ -356,12 +368,18 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width void Backend_UnloadGlyph(Backend_Glyph *glyph) { + if (glyph == NULL) + return; + free(glyph->pixels); free(glyph); } void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { + if (glyph == NULL || surface == NULL) + return; + switch (glyph->pixel_mode) { case FONT_PIXEL_MODE_LCD: From defe234ff2172793dda184854e5176d0a177f5cd Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 25 Jul 2019 00:09:10 +0100 Subject: [PATCH 037/128] Clean up some ugly formatting --- src/Backends/Rendering/SDLTexture.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 604faaa6..f31de690 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -286,7 +286,6 @@ void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) SDL_Rect sdl_rect; RectToSDLRect(rect, &sdl_rect); - // // Copy screen to surface // @@ -305,7 +304,6 @@ void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) // Cleanup SDL_FreeSurface(screen_surface); - // // Copy screen to texture // From aa728979a33d11b65bf143c87c73dc66301041e1 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 25 Jul 2019 00:39:03 +0100 Subject: [PATCH 038/128] Fix the Texture backend not rendering text the accurate buggy way A shame I have to fall back on the Surface fallback. Speaking of, I really need to replace that fallback with my software renderer. --- src/Backends/Rendering/SDLTexture.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index f31de690..1967db36 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -391,24 +391,20 @@ void Backend_UnloadGlyph(Backend_Glyph *glyph) void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { - // This is actually slightly imperfect: the SDL_Texture side of things uses alpha, not a colour-key, - // so the bug where the font is blended with the colour key doesn't occur. SDL_Textures don't support - // colour-keys, so the next best thing is relying on the software fallback, but I don't like the idea - // of uploading textures to the GPU every time a glyph is drawn. + // The SDL_Texture side of things uses alpha, not a colour-key, so the bug where the font is blended + // with the colour key doesn't occur. SDL_Textures don't support colour-keys, so the next best thing + // is relying on the software fallback. if (glyph == NULL || surface == NULL) return; - RECT rect; - rect.left = 0; - rect.top = 0; - rect.right = glyph->surface->sdl_surface->w; - rect.bottom = glyph->surface->sdl_surface->h; + SDL_Rect destination_rect = {x, y, glyph->surface->sdl_surface->w, glyph->surface->sdl_surface->h}; SDL_SetSurfaceColorMod(glyph->surface->sdl_surface, colours[0], colours[1], colours[2]); - SDL_SetTextureColorMod(glyph->surface->texture, colours[0], colours[1], colours[2]); + SDL_SetSurfaceBlendMode(glyph->surface->sdl_surface, SDL_BLENDMODE_BLEND); + SDL_BlitSurface(glyph->surface->sdl_surface, NULL, surface->sdl_surface, &destination_rect); - Backend_Blit(glyph->surface, &rect, surface, x, y, TRUE); + surface->needs_syncing = TRUE; } void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) From 0abac07aab4be5c0c702604c8ff2b5ca10893d70 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 27 Jul 2019 03:36:35 +0000 Subject: [PATCH 039/128] Note the new dependency on GLEW I wonder if I could use SDL2's SDL_GL_GetProcAddress, SDL_GL_ExtensionSupported, and SDL_GL_LoadLibrary functions to bypass needing GLEW? Then again, I'd like to remove the dependency on SDL2 at some point as well... --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index eaa19031..2ef20f75 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Cave Story Engine 2 is a decompilation of Cave Story, ported from DirectX to SDL * SDL2 * FreeType * FLTK +* GLEW (if the OpenGL backend is selected) (not currently built with CMake) ## Building From 2d73fd8bb913500551dad70de8ad9d2cd45aaf63 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 27 Jul 2019 03:42:51 +0000 Subject: [PATCH 040/128] Use GLEW to check if OpenGL 2.1 is supported --- src/Backends/Rendering/OpenGL2.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 0fc5a495..801d37eb 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -102,6 +102,10 @@ BOOL Backend_Init(SDL_Window *p_window) if (glewInit() != GLEW_OK) return FALSE; + // Check if the platform supports OpenGL 2.1 + if (!GLEW_VERSION_2_1) + return FALSE; + // Check for framebuffer object extension (is part of the core spec in OpenGL 3.0, but not 2.1) if (!GLEW_EXT_framebuffer_object) return FALSE; From 0b874153d49216f6b8b27809a8d3cf085055df5f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 29 Jul 2019 14:33:14 +0000 Subject: [PATCH 041/128] Free the string returned by SDL_GetBasePath Thanks, Fayti1703. --- src/Main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Main.cpp b/src/Main.cpp index b2e3f82f..e8bccacf 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -94,7 +94,9 @@ int GetFramePerSecound() int main(int argc, char *argv[]) { // Get executable's path - strcpy(gModulePath, SDL_GetBasePath()); + char *base_path = SDL_GetBasePath(); + strcpy(gModulePath, base_path); + SDL_free(base_path); if (gModulePath[strlen(gModulePath) - 1] == '/' || gModulePath[strlen(gModulePath) - 1] == '\\') gModulePath[strlen(gModulePath) - 1] = '\0'; // String cannot end in slash or stuff will probably break (original does this through a windows.h provided function) From 03b33adb70a04b543804f3e4d428a1ccc795fba6 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 29 Jul 2019 18:11:46 +0000 Subject: [PATCH 042/128] Switch OpenGL 2.1 backend to use vertex arrays This replaces the glBegin/glEnd stuff. Even though vertex arrays aren't removed from newer OpenGL versions like glBegin/glEnd are, they *are* deprecated, so I want to switch to VBOs eventually. --- src/Backends/Rendering/OpenGL2.cpp | 185 ++++++++++++++++++++++------- 1 file changed, 144 insertions(+), 41 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 801d37eb..bf34eb58 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -29,6 +29,9 @@ static SDL_Window *window; static SDL_GLContext context; static GLuint colour_key_program_id; static GLuint framebuffer_id; +static GLfloat vertex_buffer[4][2]; +static GLfloat texture_coordinate_buffer[4][2]; +static GLfloat colour_buffer[4][3]; static Backend_Surface framebuffer_surface; @@ -110,11 +113,17 @@ BOOL Backend_Init(SDL_Window *p_window) if (!GLEW_EXT_framebuffer_object) return FALSE; - glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, vertex_buffer); + glTexCoordPointer(2, GL_FLOAT, 0, texture_coordinate_buffer); + glColorPointer(3, GL_FLOAT, 0, colour_buffer); + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); @@ -172,17 +181,38 @@ void Backend_DrawScreen(void) glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id); - glBegin(GL_QUADS); - glColor3f(1.0f, 1.0f, 1.0f); - glTexCoord2f(0.0f, 1.0f); - glVertex2f(-1.0f, -1.0f); - glTexCoord2f(1.0f, 1.0f); - glVertex2f(1.0f, -1.0f); - glTexCoord2f(1.0f, 0.0f); - glVertex2f(1.0f, 1.0f); - glTexCoord2f(0.0f, 0.0f); - glVertex2f(-1.0f, 1.0f); - glEnd(); + colour_buffer[0][0] = 1.0f; + colour_buffer[0][1] = 1.0f; + colour_buffer[0][2] = 1.0f; + colour_buffer[1][0] = colour_buffer[0][0]; + colour_buffer[1][1] = colour_buffer[0][1]; + colour_buffer[1][2] = colour_buffer[0][2]; + colour_buffer[2][0] = colour_buffer[0][0]; + colour_buffer[2][1] = colour_buffer[0][1]; + colour_buffer[2][2] = colour_buffer[0][2]; + colour_buffer[3][0] = colour_buffer[0][0]; + colour_buffer[3][1] = colour_buffer[0][1]; + colour_buffer[3][2] = colour_buffer[0][2]; + + texture_coordinate_buffer[0][0] = 0.0f; + texture_coordinate_buffer[0][1] = 1.0f; + texture_coordinate_buffer[1][0] = 1.0f; + texture_coordinate_buffer[1][1] = 1.0f; + texture_coordinate_buffer[2][0] = 1.0f; + texture_coordinate_buffer[2][1] = 0.0f; + texture_coordinate_buffer[3][0] = 0.0f; + texture_coordinate_buffer[3][1] = 0.0f; + + vertex_buffer[0][0] = -1.0f; + vertex_buffer[0][1] = -1.0f; + vertex_buffer[1][0] = 1.0f; + vertex_buffer[1][1] = -1.0f; + vertex_buffer[2][0] = 1.0f; + vertex_buffer[2][1] = 1.0f; + vertex_buffer[3][0] = -1.0f; + vertex_buffer[3][1] = 1.0f; + + glDrawArrays(GL_QUADS, 0, 4); glPopMatrix(); @@ -254,17 +284,48 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x glBindTexture(GL_TEXTURE_2D, source_surface->texture_id); - glBegin(GL_QUADS); - glColor3f(1.0f, 1.0f, 1.0f); - glTexCoord2f((GLfloat)rect->left / (GLfloat)source_surface->width, (GLfloat)rect->top / (GLfloat)source_surface->height); - glVertex2f((GLfloat)x, (GLfloat)y); - glTexCoord2f((GLfloat)rect->right / (GLfloat)source_surface->width, (GLfloat)rect->top / (GLfloat)source_surface->height); - glVertex2f((GLfloat)x + (rect->right - rect->left), (GLfloat)y); - glTexCoord2f((GLfloat)rect->right / (GLfloat)source_surface->width, (GLfloat)rect->bottom / (GLfloat)source_surface->height); - glVertex2f((GLfloat)x + (rect->right - rect->left), (GLfloat)y + (rect->bottom - rect->top)); - glTexCoord2f((GLfloat)rect->left / (GLfloat)source_surface->width, (GLfloat)rect->bottom / (GLfloat)source_surface->height); - glVertex2f((GLfloat)x, (GLfloat)y + (rect->bottom - rect->top)); - glEnd(); + const GLfloat texture_left = (GLfloat)rect->left / (GLfloat)source_surface->width; + const GLfloat texture_right = (GLfloat)rect->right / (GLfloat)source_surface->width; + const GLfloat texture_top = (GLfloat)rect->top / (GLfloat)source_surface->height; + const GLfloat texture_bottom = (GLfloat)rect->bottom / (GLfloat)source_surface->height; + + const GLfloat vertex_left = (GLfloat)x; + const GLfloat vertex_right = (GLfloat)x + (rect->right - rect->left); + const GLfloat vertex_top = (GLfloat)y; + const GLfloat vertex_bottom = (GLfloat)y + (rect->bottom - rect->top); + + colour_buffer[0][0] = 1.0f; + colour_buffer[0][1] = 1.0f; + colour_buffer[0][2] = 1.0f; + colour_buffer[1][0] = colour_buffer[0][0]; + colour_buffer[1][1] = colour_buffer[0][1]; + colour_buffer[1][2] = colour_buffer[0][2]; + colour_buffer[2][0] = colour_buffer[0][0]; + colour_buffer[2][1] = colour_buffer[0][1]; + colour_buffer[2][2] = colour_buffer[0][2]; + colour_buffer[3][0] = colour_buffer[0][0]; + colour_buffer[3][1] = colour_buffer[0][1]; + colour_buffer[3][2] = colour_buffer[0][2]; + + texture_coordinate_buffer[0][0] = texture_left; + texture_coordinate_buffer[0][1] = texture_top; + texture_coordinate_buffer[1][0] = texture_right; + texture_coordinate_buffer[1][1] = texture_top; + texture_coordinate_buffer[2][0] = texture_right; + texture_coordinate_buffer[2][1] = texture_bottom; + texture_coordinate_buffer[3][0] = texture_left; + texture_coordinate_buffer[3][1] = texture_bottom; + + vertex_buffer[0][0] = vertex_left; + vertex_buffer[0][1] = vertex_top; + vertex_buffer[1][0] = vertex_right; + vertex_buffer[1][1] = vertex_top; + vertex_buffer[2][0] = vertex_right; + vertex_buffer[2][1] = vertex_bottom; + vertex_buffer[3][0] = vertex_left; + vertex_buffer[3][1] = vertex_bottom; + + glDrawArrays(GL_QUADS, 0, 4); } void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) @@ -300,13 +361,29 @@ static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char // Use blank default texture, for a solid colour-fill glBindTexture(GL_TEXTURE_2D, 0); - glBegin(GL_QUADS); - glColor3f(red / 255.0f, green / 255.0f, blue / 255.0f); - glVertex2f((GLfloat)rect->left, (GLfloat)rect->top); - glVertex2f((GLfloat)rect->right, (GLfloat)rect->top); - glVertex2f((GLfloat)rect->right, (GLfloat)rect->bottom); - glVertex2f((GLfloat)rect->left, (GLfloat)rect->bottom); - glEnd(); + colour_buffer[0][0] = red / 255.0f; + colour_buffer[0][1] = green / 255.0f; + colour_buffer[0][2] = blue / 255.0f; + colour_buffer[1][0] = colour_buffer[0][0]; + colour_buffer[1][1] = colour_buffer[0][1]; + colour_buffer[1][2] = colour_buffer[0][2]; + colour_buffer[2][0] = colour_buffer[0][0]; + colour_buffer[2][1] = colour_buffer[0][1]; + colour_buffer[2][2] = colour_buffer[0][2]; + colour_buffer[3][0] = colour_buffer[0][0]; + colour_buffer[3][1] = colour_buffer[0][1]; + colour_buffer[3][2] = colour_buffer[0][2]; + + vertex_buffer[0][0] = (GLfloat)rect->left; + vertex_buffer[0][1] = (GLfloat)rect->top; + vertex_buffer[1][0] = (GLfloat)rect->right; + vertex_buffer[1][1] = (GLfloat)rect->top; + vertex_buffer[2][0] = (GLfloat)rect->right; + vertex_buffer[2][1] = (GLfloat)rect->bottom; + vertex_buffer[3][0] = (GLfloat)rect->left; + vertex_buffer[3][1] = (GLfloat)rect->bottom; + + glDrawArrays(GL_QUADS, 0, 4); } void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) @@ -424,17 +501,43 @@ static void DrawGlyphCommon(Backend_Glyph *glyph, long x, long y, const unsigned glBindTexture(GL_TEXTURE_2D, glyph->texture_id); - glBegin(GL_QUADS); - glColor3f(colours[0] / 255.0f, colours[1] / 255.0f, colours[2] / 255.0f); - glTexCoord2f(0.0f, 0.0f); - glVertex2f((GLfloat)x, (GLfloat)y); - glTexCoord2f(1.0f, 0.0f); - glVertex2f((GLfloat)x + glyph->width, (GLfloat)y); - glTexCoord2f(1.0f, 1.0f); - glVertex2f((GLfloat)x + glyph->width, (GLfloat)y + glyph->height); - glTexCoord2f(0.0f, 1.0f); - glVertex2f((GLfloat)x, (GLfloat)y + glyph->height); - glEnd(); + const GLfloat vertex_left = (GLfloat)x; + const GLfloat vertex_right = (GLfloat)x + glyph->width; + const GLfloat vertex_top = (GLfloat)y; + const GLfloat vertex_bottom = (GLfloat)y + glyph->height; + + colour_buffer[0][0] = colours[0] / 255.0f; + colour_buffer[0][1] = colours[1] / 255.0f; + colour_buffer[0][2] = colours[2] / 255.0f; + colour_buffer[1][0] = colour_buffer[0][0]; + colour_buffer[1][1] = colour_buffer[0][1]; + colour_buffer[1][2] = colour_buffer[0][2]; + colour_buffer[2][0] = colour_buffer[0][0]; + colour_buffer[2][1] = colour_buffer[0][1]; + colour_buffer[2][2] = colour_buffer[0][2]; + colour_buffer[3][0] = colour_buffer[0][0]; + colour_buffer[3][1] = colour_buffer[0][1]; + colour_buffer[3][2] = colour_buffer[0][2]; + + texture_coordinate_buffer[0][0] = 0.0f; + texture_coordinate_buffer[0][1] = 0.0f; + texture_coordinate_buffer[1][0] = 1.0f; + texture_coordinate_buffer[1][1] = 0.0f; + texture_coordinate_buffer[2][0] = 1.0f; + texture_coordinate_buffer[2][1] = 1.0f; + texture_coordinate_buffer[3][0] = 0.0f; + texture_coordinate_buffer[3][1] = 1.0f; + + vertex_buffer[0][0] = vertex_left; + vertex_buffer[0][1] = vertex_top; + vertex_buffer[1][0] = vertex_right; + vertex_buffer[1][1] = vertex_top; + vertex_buffer[2][0] = vertex_right; + vertex_buffer[2][1] = vertex_bottom; + vertex_buffer[3][0] = vertex_left; + vertex_buffer[3][1] = vertex_bottom; + + glDrawArrays(GL_QUADS, 0, 4); } void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) From 348a691c6c7f6ae918ebdc861b43f74439606375 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 02:49:07 +0000 Subject: [PATCH 043/128] GLU is unneeded --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba0f7720..fb2ff037 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,7 +251,7 @@ if(RENDERER MATCHES "OpenGL2") find_package(GLEW REQUIRED) target_link_libraries(CSE2 GLEW::GLEW) find_package(OpenGL REQUIRED) - target_link_libraries(CSE2 OpenGL::GL OpenGL::GLU) + target_link_libraries(CSE2 OpenGL::GL) elseif(RENDERER MATCHES "Texture") target_sources(CSE2 PRIVATE "src/Backends/Rendering/SDLTexture.cpp") elseif(RENDERER MATCHES "Surface") From 64f7a2eae3fbe666241211487e22196fa5485100 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 02:52:43 +0000 Subject: [PATCH 044/128] Use GL_LUMINANCE_ALPHA instead of GL_ALPHA GL_ALPHA sets the RGB values to 0.0, but I want them set to 1.0 --- src/Backends/Rendering/OpenGL2.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index bf34eb58..21327e5c 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -428,7 +428,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width if (glyph == NULL) return NULL; - const int destination_pitch = (width + 3) & ~3; // Round up to the nearest 4 (OpenGL needs this) + const int destination_pitch = ((width * 2) + 3) & ~3; // Round up to the nearest 4 (OpenGL needs this) unsigned char *buffer = (unsigned char*)malloc(destination_pitch * height); @@ -450,6 +450,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width for (unsigned int x = 0; x < width; ++x) { + *destination_pointer++ = 0xFF; *destination_pointer++ = (unsigned char)(pow((double)*source_pointer++ / (total_greys - 1), 1.0 / 1.8) * 255.0); } } @@ -464,6 +465,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width for (unsigned int x = 0; x < width; ++x) { + *destination_pointer++ = 0xFF; *destination_pointer++ = *source_pointer++ ? 0xFF : 0; } } @@ -473,7 +475,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width glGenTextures(1, &glyph->texture_id); glBindTexture(GL_TEXTURE_2D, glyph->texture_id); - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer); + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE8_ALPHA8, width, height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, buffer); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); From 9cc1a5a0989d9cfe242fde830077bb45a748d75c Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 02:55:22 +0000 Subject: [PATCH 045/128] Change colour_buffer to unsigned bytes instead of floats --- src/Backends/Rendering/OpenGL2.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 21327e5c..3da668a7 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -31,7 +31,7 @@ static GLuint colour_key_program_id; static GLuint framebuffer_id; static GLfloat vertex_buffer[4][2]; static GLfloat texture_coordinate_buffer[4][2]; -static GLfloat colour_buffer[4][3]; +static GLubyte colour_buffer[4][3]; static Backend_Surface framebuffer_surface; @@ -122,7 +122,7 @@ BOOL Backend_Init(SDL_Window *p_window) glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(2, GL_FLOAT, 0, vertex_buffer); glTexCoordPointer(2, GL_FLOAT, 0, texture_coordinate_buffer); - glColorPointer(3, GL_FLOAT, 0, colour_buffer); + glColorPointer(3, GL_UNSIGNED_BYTE, 0, colour_buffer); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); @@ -181,9 +181,9 @@ void Backend_DrawScreen(void) glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id); - colour_buffer[0][0] = 1.0f; - colour_buffer[0][1] = 1.0f; - colour_buffer[0][2] = 1.0f; + colour_buffer[0][0] = 0xFF; + colour_buffer[0][1] = 0xFF; + colour_buffer[0][2] = 0xFF; colour_buffer[1][0] = colour_buffer[0][0]; colour_buffer[1][1] = colour_buffer[0][1]; colour_buffer[1][2] = colour_buffer[0][2]; @@ -294,9 +294,9 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x const GLfloat vertex_top = (GLfloat)y; const GLfloat vertex_bottom = (GLfloat)y + (rect->bottom - rect->top); - colour_buffer[0][0] = 1.0f; - colour_buffer[0][1] = 1.0f; - colour_buffer[0][2] = 1.0f; + colour_buffer[0][0] = 0xFF; + colour_buffer[0][1] = 0xFF; + colour_buffer[0][2] = 0xFF; colour_buffer[1][0] = colour_buffer[0][0]; colour_buffer[1][1] = colour_buffer[0][1]; colour_buffer[1][2] = colour_buffer[0][2]; @@ -361,9 +361,9 @@ static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char // Use blank default texture, for a solid colour-fill glBindTexture(GL_TEXTURE_2D, 0); - colour_buffer[0][0] = red / 255.0f; - colour_buffer[0][1] = green / 255.0f; - colour_buffer[0][2] = blue / 255.0f; + colour_buffer[0][0] = red; + colour_buffer[0][1] = green; + colour_buffer[0][2] = blue; colour_buffer[1][0] = colour_buffer[0][0]; colour_buffer[1][1] = colour_buffer[0][1]; colour_buffer[1][2] = colour_buffer[0][2]; @@ -508,9 +508,9 @@ static void DrawGlyphCommon(Backend_Glyph *glyph, long x, long y, const unsigned const GLfloat vertex_top = (GLfloat)y; const GLfloat vertex_bottom = (GLfloat)y + glyph->height; - colour_buffer[0][0] = colours[0] / 255.0f; - colour_buffer[0][1] = colours[1] / 255.0f; - colour_buffer[0][2] = colours[2] / 255.0f; + colour_buffer[0][0] = colours[0]; + colour_buffer[0][1] = colours[1]; + colour_buffer[0][2] = colours[2]; colour_buffer[1][0] = colour_buffer[0][0]; colour_buffer[1][1] = colour_buffer[0][1]; colour_buffer[1][2] = colour_buffer[0][2]; From f0809fb901caebf2c0d9778e19e6daa777d32da1 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 02:57:11 +0000 Subject: [PATCH 046/128] Change colour_buffer assignments --- src/Backends/Rendering/OpenGL2.cpp | 60 ++++++------------------------ 1 file changed, 12 insertions(+), 48 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 3da668a7..ef6ec0d5 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -181,18 +181,9 @@ void Backend_DrawScreen(void) glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id); - colour_buffer[0][0] = 0xFF; - colour_buffer[0][1] = 0xFF; - colour_buffer[0][2] = 0xFF; - colour_buffer[1][0] = colour_buffer[0][0]; - colour_buffer[1][1] = colour_buffer[0][1]; - colour_buffer[1][2] = colour_buffer[0][2]; - colour_buffer[2][0] = colour_buffer[0][0]; - colour_buffer[2][1] = colour_buffer[0][1]; - colour_buffer[2][2] = colour_buffer[0][2]; - colour_buffer[3][0] = colour_buffer[0][0]; - colour_buffer[3][1] = colour_buffer[0][1]; - colour_buffer[3][2] = colour_buffer[0][2]; + colour_buffer[0][0] = colour_buffer[1][0] = colour_buffer[2][0] = colour_buffer[3][0] = 0xFF; + colour_buffer[0][1] = colour_buffer[1][1] = colour_buffer[2][1] = colour_buffer[3][1] = 0xFF; + colour_buffer[0][2] = colour_buffer[1][2] = colour_buffer[2][2] = colour_buffer[3][2] = 0xFF; texture_coordinate_buffer[0][0] = 0.0f; texture_coordinate_buffer[0][1] = 1.0f; @@ -294,18 +285,9 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x const GLfloat vertex_top = (GLfloat)y; const GLfloat vertex_bottom = (GLfloat)y + (rect->bottom - rect->top); - colour_buffer[0][0] = 0xFF; - colour_buffer[0][1] = 0xFF; - colour_buffer[0][2] = 0xFF; - colour_buffer[1][0] = colour_buffer[0][0]; - colour_buffer[1][1] = colour_buffer[0][1]; - colour_buffer[1][2] = colour_buffer[0][2]; - colour_buffer[2][0] = colour_buffer[0][0]; - colour_buffer[2][1] = colour_buffer[0][1]; - colour_buffer[2][2] = colour_buffer[0][2]; - colour_buffer[3][0] = colour_buffer[0][0]; - colour_buffer[3][1] = colour_buffer[0][1]; - colour_buffer[3][2] = colour_buffer[0][2]; + colour_buffer[0][0] = colour_buffer[1][0] = colour_buffer[2][0] = colour_buffer[3][0] = 0xFF; + colour_buffer[0][1] = colour_buffer[1][1] = colour_buffer[2][1] = colour_buffer[3][1] = 0xFF; + colour_buffer[0][2] = colour_buffer[1][2] = colour_buffer[2][2] = colour_buffer[3][2] = 0xFF; texture_coordinate_buffer[0][0] = texture_left; texture_coordinate_buffer[0][1] = texture_top; @@ -361,18 +343,9 @@ static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char // Use blank default texture, for a solid colour-fill glBindTexture(GL_TEXTURE_2D, 0); - colour_buffer[0][0] = red; - colour_buffer[0][1] = green; - colour_buffer[0][2] = blue; - colour_buffer[1][0] = colour_buffer[0][0]; - colour_buffer[1][1] = colour_buffer[0][1]; - colour_buffer[1][2] = colour_buffer[0][2]; - colour_buffer[2][0] = colour_buffer[0][0]; - colour_buffer[2][1] = colour_buffer[0][1]; - colour_buffer[2][2] = colour_buffer[0][2]; - colour_buffer[3][0] = colour_buffer[0][0]; - colour_buffer[3][1] = colour_buffer[0][1]; - colour_buffer[3][2] = colour_buffer[0][2]; + colour_buffer[0][0] = colour_buffer[1][0] = colour_buffer[2][0] = colour_buffer[3][0] = red; + colour_buffer[0][1] = colour_buffer[1][1] = colour_buffer[2][1] = colour_buffer[3][1] = green; + colour_buffer[0][2] = colour_buffer[1][2] = colour_buffer[2][2] = colour_buffer[3][2] = blue; vertex_buffer[0][0] = (GLfloat)rect->left; vertex_buffer[0][1] = (GLfloat)rect->top; @@ -508,18 +481,9 @@ static void DrawGlyphCommon(Backend_Glyph *glyph, long x, long y, const unsigned const GLfloat vertex_top = (GLfloat)y; const GLfloat vertex_bottom = (GLfloat)y + glyph->height; - colour_buffer[0][0] = colours[0]; - colour_buffer[0][1] = colours[1]; - colour_buffer[0][2] = colours[2]; - colour_buffer[1][0] = colour_buffer[0][0]; - colour_buffer[1][1] = colour_buffer[0][1]; - colour_buffer[1][2] = colour_buffer[0][2]; - colour_buffer[2][0] = colour_buffer[0][0]; - colour_buffer[2][1] = colour_buffer[0][1]; - colour_buffer[2][2] = colour_buffer[0][2]; - colour_buffer[3][0] = colour_buffer[0][0]; - colour_buffer[3][1] = colour_buffer[0][1]; - colour_buffer[3][2] = colour_buffer[0][2]; + colour_buffer[0][0] = colour_buffer[1][0] = colour_buffer[2][0] = colour_buffer[3][0] = colours[0]; + colour_buffer[0][1] = colour_buffer[1][1] = colour_buffer[2][1] = colour_buffer[3][1] = colours[1]; + colour_buffer[0][2] = colour_buffer[1][2] = colour_buffer[2][2] = colour_buffer[3][2] = colours[2]; texture_coordinate_buffer[0][0] = 0.0f; texture_coordinate_buffer[0][1] = 0.0f; From 92476bd30a8a14cddac14a74b71a8eec3eb0a7ea Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 03:00:56 +0000 Subject: [PATCH 047/128] Made the OpenGL 2.1 backend use custom shaders Edging towards OpenGL 3. --- src/Backends/Rendering/OpenGL2.cpp | 50 +++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index ef6ec0d5..2d0003b0 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -27,6 +27,7 @@ typedef struct Backend_Glyph static SDL_Window *window; static SDL_GLContext context; +static GLuint normal_program_id; static GLuint colour_key_program_id; static GLuint framebuffer_id; static GLfloat vertex_buffer[4][2]; @@ -35,7 +36,26 @@ static GLubyte colour_buffer[4][3]; static Backend_Surface framebuffer_surface; -static const GLchar *fragment_shader_source = " \ +static const GLchar *vertex_shader_source = " \ +#version 120\n \ +void main() \ +{ \ + gl_FrontColor = gl_Color; \ + gl_TexCoord[0] = gl_MultiTexCoord0; \ + gl_Position = gl_ModelViewMatrix * gl_Vertex; \ +} \ +"; + +static const GLchar *fragment_shader_source_normal = " \ +#version 120\n \ +uniform sampler2D tex; \ +void main() \ +{ \ + gl_FragColor = gl_Color * texture2D(tex, gl_TexCoord[0].st); \ +} \ +"; + +static const GLchar *fragment_shader_source_colour_key = " \ #version 120\n \ uniform sampler2D tex; \ void main() \ @@ -49,12 +69,22 @@ void main() \ } \ "; -static GLuint CompileShader(const char *fragment_shader_source) +static GLuint CompileShader(const char *vertex_shader_source, const char *fragment_shader_source) { GLint shader_status; GLuint program_id = glCreateProgram(); + GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vertex_shader, 1, &vertex_shader_source, NULL); + glCompileShader(vertex_shader); + + glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &shader_status); + if (shader_status != GL_TRUE) + return 0; + + glAttachShader(program_id, vertex_shader); + GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragment_shader, 1, &fragment_shader_source, NULL); glCompileShader(fragment_shader); @@ -134,8 +164,12 @@ BOOL Backend_Init(SDL_Window *p_window) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - // Set up our colour-key-enabled fragment shader - colour_key_program_id = CompileShader(fragment_shader_source); + // Set up our shaders + normal_program_id = CompileShader(vertex_shader_source, fragment_shader_source_normal); + colour_key_program_id = CompileShader(vertex_shader_source, fragment_shader_source_colour_key); + + if (normal_program_id == 0 || colour_key_program_id == 0) + printf("Failed to compile shaders\n"); // Set up framebuffer (used for surface-to-surface blitting) glGenFramebuffersEXT(1, &framebuffer_id); @@ -165,7 +199,7 @@ void Backend_Deinit(void) void Backend_DrawScreen(void) { // Disable colour-keying - glUseProgram(0); + glUseProgram(normal_program_id); // Target actual screen, and not our framebuffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); @@ -271,7 +305,7 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x return; // Switch to colour-key shader if we have to - glUseProgram(colour_key ? colour_key_program_id : 0); + glUseProgram(colour_key ? colour_key_program_id : normal_program_id); glBindTexture(GL_TEXTURE_2D, source_surface->texture_id); @@ -338,7 +372,7 @@ static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char return; // Disable colour-keying - glUseProgram(0); + glUseProgram(normal_program_id); // Use blank default texture, for a solid colour-fill glBindTexture(GL_TEXTURE_2D, 0); @@ -472,7 +506,7 @@ void Backend_UnloadGlyph(Backend_Glyph *glyph) static void DrawGlyphCommon(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { // Disable colour-keying - glUseProgram(0); + glUseProgram(normal_program_id); glBindTexture(GL_TEXTURE_2D, glyph->texture_id); From d9929a8e1fb5f2ae8c5532aea16c8d3dc04bd9a0 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 03:04:32 +0000 Subject: [PATCH 048/128] This shouldn't be needed anymore --- src/Backends/Rendering/OpenGL2.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 2d0003b0..0d9d65bf 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -143,7 +143,6 @@ BOOL Backend_Init(SDL_Window *p_window) if (!GLEW_EXT_framebuffer_object) return FALSE; - glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); From a5fd0cebc0e56901d6797268b0f9e3f2890c1684 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 03:39:30 +0000 Subject: [PATCH 049/128] Use specialised shaders for everything Saves us having to do a bunch of extra legwork (setting up the blank default texture, setting the colour modifier to white, etc.), and should improve performance. While I was at it, I made the colour modifier a uniform, so it only has to be set once per quad, rather than once per vertex. --- src/Backends/Rendering/OpenGL2.cpp | 106 ++++++++++++++++------------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 0d9d65bf..8d4c50ca 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -27,40 +27,53 @@ typedef struct Backend_Glyph static SDL_Window *window; static SDL_GLContext context; -static GLuint normal_program_id; -static GLuint colour_key_program_id; + +static GLuint program_texture; +static GLuint program_texture_colour_key; +static GLuint program_colour_fill; +static GLuint program_glyph; + +static GLint uniform_colour_fill_colour; +static GLint uniform_glyph_colour; + static GLuint framebuffer_id; static GLfloat vertex_buffer[4][2]; static GLfloat texture_coordinate_buffer[4][2]; -static GLubyte colour_buffer[4][3]; static Backend_Surface framebuffer_surface; -static const GLchar *vertex_shader_source = " \ +static const GLchar *vertex_shader_plain = " \ +#version 120\n \ +void main() \ +{ \ + gl_Position = gl_ModelViewMatrix * gl_Vertex; \ +} \ +"; + +static const GLchar *vertex_shader_texture = " \ #version 120\n \ void main() \ { \ - gl_FrontColor = gl_Color; \ gl_TexCoord[0] = gl_MultiTexCoord0; \ gl_Position = gl_ModelViewMatrix * gl_Vertex; \ } \ "; -static const GLchar *fragment_shader_source_normal = " \ +static const GLchar *fragment_shader_texture = " \ #version 120\n \ uniform sampler2D tex; \ void main() \ { \ - gl_FragColor = gl_Color * texture2D(tex, gl_TexCoord[0].st); \ + gl_FragColor = texture2D(tex, gl_TexCoord[0].st); \ } \ "; -static const GLchar *fragment_shader_source_colour_key = " \ +static const GLchar *fragment_shader_texture_colour_key = " \ #version 120\n \ uniform sampler2D tex; \ void main() \ { \ - vec4 colour = gl_Color * texture2D(tex, gl_TexCoord[0].st); \ + vec4 colour = texture2D(tex, gl_TexCoord[0].st); \ \ if (colour.xyz == vec3(0.0f, 0.0f, 0.0f)) \ discard; \ @@ -69,6 +82,25 @@ void main() \ } \ "; +static const GLchar *fragment_shader_colour_fill = " \ +#version 120\n \ +uniform vec4 colour; \ +void main() \ +{ \ + gl_FragColor = colour; \ +} \ +"; + +static const GLchar *fragment_shader_glyph = " \ +#version 120\n \ +uniform sampler2D tex; \ +uniform vec4 colour; \ +void main() \ +{ \ + gl_FragColor = colour * texture2D(tex, gl_TexCoord[0].st); \ +} \ +"; + static GLuint CompileShader(const char *vertex_shader_source, const char *fragment_shader_source) { GLint shader_status; @@ -147,29 +179,26 @@ BOOL Backend_Init(SDL_Window *p_window) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(2, GL_FLOAT, 0, vertex_buffer); glTexCoordPointer(2, GL_FLOAT, 0, texture_coordinate_buffer); - glColorPointer(3, GL_UNSIGNED_BYTE, 0, colour_buffer); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); - // Set up blank default texture (it seems to be black by default, which sucks for colour modulation) - const unsigned char white_pixel[3] = {0xFF, 0xFF, 0xFF}; - glBindTexture(GL_TEXTURE_2D, 0); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, white_pixel); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - // Set up our shaders - normal_program_id = CompileShader(vertex_shader_source, fragment_shader_source_normal); - colour_key_program_id = CompileShader(vertex_shader_source, fragment_shader_source_colour_key); + program_texture = CompileShader(vertex_shader_texture, fragment_shader_texture); + program_texture_colour_key = CompileShader(vertex_shader_texture, fragment_shader_texture_colour_key); + program_colour_fill = CompileShader(vertex_shader_plain, fragment_shader_colour_fill); + program_glyph = CompileShader(vertex_shader_texture, fragment_shader_glyph); - if (normal_program_id == 0 || colour_key_program_id == 0) + if (program_texture == 0 || program_texture_colour_key == 0 || program_colour_fill == 0 || program_glyph == 0) printf("Failed to compile shaders\n"); + // Get shader uniforms + uniform_colour_fill_colour = glGetUniformLocation(program_colour_fill, "colour"); + uniform_glyph_colour = glGetUniformLocation(program_glyph, "colour"); + // Set up framebuffer (used for surface-to-surface blitting) glGenFramebuffersEXT(1, &framebuffer_id); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_id); @@ -191,14 +220,16 @@ void Backend_Deinit(void) { glDeleteTextures(1, &framebuffer_surface.texture_id); glDeleteFramebuffersEXT(1, &framebuffer_id); - glDeleteProgram(colour_key_program_id); + glDeleteProgram(program_glyph); + glDeleteProgram(program_colour_fill); + glDeleteProgram(program_texture_colour_key); + glDeleteProgram(program_texture); SDL_GL_DeleteContext(context); } void Backend_DrawScreen(void) { - // Disable colour-keying - glUseProgram(normal_program_id); + glUseProgram(program_texture); // Target actual screen, and not our framebuffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); @@ -214,10 +245,6 @@ void Backend_DrawScreen(void) glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id); - colour_buffer[0][0] = colour_buffer[1][0] = colour_buffer[2][0] = colour_buffer[3][0] = 0xFF; - colour_buffer[0][1] = colour_buffer[1][1] = colour_buffer[2][1] = colour_buffer[3][1] = 0xFF; - colour_buffer[0][2] = colour_buffer[1][2] = colour_buffer[2][2] = colour_buffer[3][2] = 0xFF; - texture_coordinate_buffer[0][0] = 0.0f; texture_coordinate_buffer[0][1] = 1.0f; texture_coordinate_buffer[1][0] = 1.0f; @@ -304,7 +331,7 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x return; // Switch to colour-key shader if we have to - glUseProgram(colour_key ? colour_key_program_id : normal_program_id); + glUseProgram(colour_key ? program_texture_colour_key : program_texture); glBindTexture(GL_TEXTURE_2D, source_surface->texture_id); @@ -318,10 +345,6 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x const GLfloat vertex_top = (GLfloat)y; const GLfloat vertex_bottom = (GLfloat)y + (rect->bottom - rect->top); - colour_buffer[0][0] = colour_buffer[1][0] = colour_buffer[2][0] = colour_buffer[3][0] = 0xFF; - colour_buffer[0][1] = colour_buffer[1][1] = colour_buffer[2][1] = colour_buffer[3][1] = 0xFF; - colour_buffer[0][2] = colour_buffer[1][2] = colour_buffer[2][2] = colour_buffer[3][2] = 0xFF; - texture_coordinate_buffer[0][0] = texture_left; texture_coordinate_buffer[0][1] = texture_top; texture_coordinate_buffer[1][0] = texture_right; @@ -370,15 +393,9 @@ static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char if (rect->right - rect->left < 0 || rect->bottom - rect->top < 0) return; - // Disable colour-keying - glUseProgram(normal_program_id); + glUseProgram(program_colour_fill); - // Use blank default texture, for a solid colour-fill - glBindTexture(GL_TEXTURE_2D, 0); - - colour_buffer[0][0] = colour_buffer[1][0] = colour_buffer[2][0] = colour_buffer[3][0] = red; - colour_buffer[0][1] = colour_buffer[1][1] = colour_buffer[2][1] = colour_buffer[3][1] = green; - colour_buffer[0][2] = colour_buffer[1][2] = colour_buffer[2][2] = colour_buffer[3][2] = blue; + glUniform4f(uniform_colour_fill_colour, red / 255.0f, green / 255.0f, blue / 255.0f, 1.0f); vertex_buffer[0][0] = (GLfloat)rect->left; vertex_buffer[0][1] = (GLfloat)rect->top; @@ -504,8 +521,7 @@ void Backend_UnloadGlyph(Backend_Glyph *glyph) static void DrawGlyphCommon(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { - // Disable colour-keying - glUseProgram(normal_program_id); + glUseProgram(program_glyph); glBindTexture(GL_TEXTURE_2D, glyph->texture_id); @@ -514,9 +530,7 @@ static void DrawGlyphCommon(Backend_Glyph *glyph, long x, long y, const unsigned const GLfloat vertex_top = (GLfloat)y; const GLfloat vertex_bottom = (GLfloat)y + glyph->height; - colour_buffer[0][0] = colour_buffer[1][0] = colour_buffer[2][0] = colour_buffer[3][0] = colours[0]; - colour_buffer[0][1] = colour_buffer[1][1] = colour_buffer[2][1] = colour_buffer[3][1] = colours[1]; - colour_buffer[0][2] = colour_buffer[1][2] = colour_buffer[2][2] = colour_buffer[3][2] = colours[2]; + glUniform4f(uniform_glyph_colour, colours[0] / 255.0f, colours[1] / 255.0f, colours[2] / 255.0f, 1.0f); texture_coordinate_buffer[0][0] = 0.0f; texture_coordinate_buffer[0][1] = 0.0f; From 3973419cef3c0f13ba3634b369f973d9d4f73af4 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 03:51:18 +0000 Subject: [PATCH 050/128] Fix Makefile when building SDLSurface backend --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0b74b148..e465804c 100644 --- a/Makefile +++ b/Makefile @@ -220,7 +220,7 @@ ifeq ($(RENDERER), OpenGL2) else ifeq ($(RENDERER), Texture) SOURCES += Backends/Rendering/SDLTexture else ifeq ($(RENDERER), Surface) - SOURCES += Backends/Rendering/Software + SOURCES += Backends/Rendering/SDLSurface else ifeq ($(RENDERER), Software) SOURCES += Backends/Rendering/Software else From 42765792bcf3f79b850edaad6738d49303199437 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 04:41:46 +0000 Subject: [PATCH 051/128] Shut up some warnings --- src/Backends/Rendering/SDLSurface.cpp | 2 +- src/Backends/Rendering/SDLTexture.cpp | 6 +++--- src/Backends/Rendering/Software.cpp | 2 +- src/NpcTbl.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 56a4cc85..41250590 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -106,7 +106,7 @@ unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch) void Backend_Unlock(Backend_Surface *surface) { - + (void)surface; } void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 1967db36..5855c9da 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -207,7 +207,7 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur SDL_Rect source_rect; RectToSDLRect(rect, &source_rect); - SDL_Rect destination_rect = {x, y, source_rect.w, source_rect.h}; + SDL_Rect destination_rect = {(int)x, (int)y, source_rect.w, source_rect.h}; // Blit the surface SDL_SetSurfaceBlendMode(source_surface->sdl_surface, colour_key ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE); @@ -234,7 +234,7 @@ void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, lon SDL_Rect source_rect; RectToSDLRect(rect, &source_rect); - SDL_Rect destination_rect = {x, y, source_rect.w, source_rect.h}; + SDL_Rect destination_rect = {(int)x, (int)y, source_rect.w, source_rect.h}; // Blit the texture SDL_SetTextureBlendMode(source_surface->texture, colour_key ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE); @@ -398,7 +398,7 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l if (glyph == NULL || surface == NULL) return; - SDL_Rect destination_rect = {x, y, glyph->surface->sdl_surface->w, glyph->surface->sdl_surface->h}; + SDL_Rect destination_rect = {(int)x, (int)y, glyph->surface->sdl_surface->w, glyph->surface->sdl_surface->h}; SDL_SetSurfaceColorMod(glyph->surface->sdl_surface, colours[0], colours[1], colours[2]); SDL_SetSurfaceBlendMode(glyph->surface->sdl_surface, SDL_BLENDMODE_BLEND); diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 0f88e668..6294fd98 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -111,7 +111,7 @@ unsigned char* Backend_Lock(Backend_Surface *surface, unsigned int *pitch) void Backend_Unlock(Backend_Surface *surface) { - + (void)surface; } void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp index 7a653b99..56a46349 100644 --- a/src/NpcTbl.cpp +++ b/src/NpcTbl.cpp @@ -17,7 +17,7 @@ BOOL LoadNpcTable(const char *path) FILE *fp; long n; long num; - unsigned long size; + long size; size = GetFileSizeLong(path); if (size == -1) From eab2a80ae522d22b763846b0674c401647db9602 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 04:52:31 +0000 Subject: [PATCH 052/128] Remove some vestigal matrix code --- src/Backends/Rendering/OpenGL2.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 8d4c50ca..cb4f7a09 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -236,11 +236,7 @@ void Backend_DrawScreen(void) glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); - glLoadIdentity(); - glOrtho(0.0, framebuffer_surface.width, 0.0, framebuffer_surface.height, 1.0, -1.0); - // Draw framebuffer to screen - glPushMatrix(); glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id); @@ -265,8 +261,6 @@ void Backend_DrawScreen(void) glDrawArrays(GL_QUADS, 0, 4); - glPopMatrix(); - SDL_GL_SwapWindow(window); // According to https://www.khronos.org/opengl/wiki/Common_Mistakes#Swap_Buffers From bd731321f2f5b9c5654f59401ecd55b8a4206a17 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 04:54:22 +0000 Subject: [PATCH 053/128] Use triangle fans instead of quads Quads are Legacy OpenGL --- src/Backends/Rendering/OpenGL2.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index cb4f7a09..89eb11e6 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -259,7 +259,7 @@ void Backend_DrawScreen(void) vertex_buffer[3][0] = -1.0f; vertex_buffer[3][1] = 1.0f; - glDrawArrays(GL_QUADS, 0, 4); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); SDL_GL_SwapWindow(window); @@ -357,7 +357,7 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x vertex_buffer[3][0] = vertex_left; vertex_buffer[3][1] = vertex_bottom; - glDrawArrays(GL_QUADS, 0, 4); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) @@ -400,7 +400,7 @@ static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char vertex_buffer[3][0] = (GLfloat)rect->left; vertex_buffer[3][1] = (GLfloat)rect->bottom; - glDrawArrays(GL_QUADS, 0, 4); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) @@ -544,7 +544,7 @@ static void DrawGlyphCommon(Backend_Glyph *glyph, long x, long y, const unsigned vertex_buffer[3][0] = vertex_left; vertex_buffer[3][1] = vertex_bottom; - glDrawArrays(GL_QUADS, 0, 4); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) From 106827c2ee1bc636384e6f99bb6574795fa08010 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 05:49:39 +0000 Subject: [PATCH 054/128] No more Legacy OpenGL ModelView matrix I'd replace it with a custom matrix, but I get the feeling the overhead of uploading a 4x4 matrix every quad is higher than just manipulating the vertexes CPU-side --- src/Backends/Rendering/OpenGL2.cpp | 92 +++++++++++++++--------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 89eb11e6..99c2d4ee 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -46,7 +46,7 @@ static const GLchar *vertex_shader_plain = " \ #version 120\n \ void main() \ { \ - gl_Position = gl_ModelViewMatrix * gl_Vertex; \ + gl_Position = gl_Vertex; \ } \ "; @@ -55,7 +55,7 @@ static const GLchar *vertex_shader_texture = " \ void main() \ { \ gl_TexCoord[0] = gl_MultiTexCoord0; \ - gl_Position = gl_ModelViewMatrix * gl_Vertex; \ + gl_Position = gl_Vertex; \ } \ "; @@ -136,16 +136,6 @@ static GLuint CompileShader(const char *vertex_shader_source, const char *fragme return program_id; } -static void SetRenderTarget(Backend_Surface *surface) -{ - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); - - glViewport(0, 0, surface->width, surface->height); - - glLoadIdentity(); - glOrtho(0.0, surface->width, 0.0, surface->height, 1.0, -1.0); -} - SDL_Window* Backend_CreateWindow(const char *title, int width, int height) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); @@ -319,7 +309,7 @@ void Backend_Unlock(Backend_Surface *surface) free(surface->pixels); } -static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) +static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) { if (rect->right - rect->left < 0 || rect->bottom - rect->top < 0) return; @@ -334,10 +324,10 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x const GLfloat texture_top = (GLfloat)rect->top / (GLfloat)source_surface->height; const GLfloat texture_bottom = (GLfloat)rect->bottom / (GLfloat)source_surface->height; - const GLfloat vertex_left = (GLfloat)x; - const GLfloat vertex_right = (GLfloat)x + (rect->right - rect->left); - const GLfloat vertex_top = (GLfloat)y; - const GLfloat vertex_bottom = (GLfloat)y + (rect->bottom - rect->top); + const GLfloat vertex_left = (x * (2.0f / destination_surface->width)) - 1.0f; + const GLfloat vertex_right = ((x + (rect->right - rect->left)) * (2.0f / destination_surface->width)) - 1.0f; + const GLfloat vertex_top = (y * (2.0f / destination_surface->height)) - 1.0f; + const GLfloat vertex_bottom = ((y + (rect->bottom - rect->top)) * (2.0f / destination_surface->height)) - 1.0f; texture_coordinate_buffer[0][0] = texture_left; texture_coordinate_buffer[0][1] = texture_top; @@ -366,9 +356,10 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur return; // Point our framebuffer to the destination texture - SetRenderTarget(destination_surface); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, destination_surface->texture_id, 0); + glViewport(0, 0, destination_surface->width, destination_surface->height); - BlitCommon(source_surface, rect, x, y, colour_key); + BlitCommon(source_surface, rect, destination_surface, x, y, colour_key); } void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) @@ -377,12 +368,13 @@ void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, lon return; // Point our framebuffer to the screen texture - SetRenderTarget(&framebuffer_surface); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); - BlitCommon(source_surface, rect, x, y, colour_key); + BlitCommon(source_surface, rect, &framebuffer_surface, x, y, colour_key); } -static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +static void ColourFillCommon(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { if (rect->right - rect->left < 0 || rect->bottom - rect->top < 0) return; @@ -391,14 +383,19 @@ static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char glUniform4f(uniform_colour_fill_colour, red / 255.0f, green / 255.0f, blue / 255.0f, 1.0f); - vertex_buffer[0][0] = (GLfloat)rect->left; - vertex_buffer[0][1] = (GLfloat)rect->top; - vertex_buffer[1][0] = (GLfloat)rect->right; - vertex_buffer[1][1] = (GLfloat)rect->top; - vertex_buffer[2][0] = (GLfloat)rect->right; - vertex_buffer[2][1] = (GLfloat)rect->bottom; - vertex_buffer[3][0] = (GLfloat)rect->left; - vertex_buffer[3][1] = (GLfloat)rect->bottom; + const GLfloat vertex_left = (rect->left * (2.0f / surface->width)) - 1.0f; + const GLfloat vertex_right = (rect->right * (2.0f / surface->width)) - 1.0f; + const GLfloat vertex_top = (rect->top * (2.0f / surface->height)) - 1.0f; + const GLfloat vertex_bottom = (rect->bottom * (2.0f / surface->height)) - 1.0f; + + vertex_buffer[0][0] = vertex_left; + vertex_buffer[0][1] = vertex_top; + vertex_buffer[1][0] = vertex_right; + vertex_buffer[1][1] = vertex_top; + vertex_buffer[2][0] = vertex_right; + vertex_buffer[2][1] = vertex_bottom; + vertex_buffer[3][0] = vertex_left; + vertex_buffer[3][1] = vertex_bottom; glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } @@ -409,17 +406,19 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha return; // Point our framebuffer to the destination texture - SetRenderTarget(surface); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + glViewport(0, 0, surface->width, surface->height); - ColourFillCommon(rect, red, green, blue); + ColourFillCommon(surface, rect, red, green, blue); } void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { // Point our framebuffer to the screen texture - SetRenderTarget(&framebuffer_surface); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); - ColourFillCommon(rect, red, green, blue); + ColourFillCommon(&framebuffer_surface, rect, red, green, blue); } void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) @@ -428,9 +427,10 @@ void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) return; // Point our framebuffer to the destination texture - SetRenderTarget(surface); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + glViewport(0, 0, surface->width, surface->height); - BlitCommon(&framebuffer_surface, rect, rect->left, rect->top, FALSE); + BlitCommon(&framebuffer_surface, rect, surface, rect->left, rect->top, FALSE); } BOOL Backend_SupportsSubpixelGlyph(void) @@ -513,16 +513,16 @@ void Backend_UnloadGlyph(Backend_Glyph *glyph) free(glyph); } -static void DrawGlyphCommon(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) +static void DrawGlyphCommon(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { glUseProgram(program_glyph); glBindTexture(GL_TEXTURE_2D, glyph->texture_id); - const GLfloat vertex_left = (GLfloat)x; - const GLfloat vertex_right = (GLfloat)x + glyph->width; - const GLfloat vertex_top = (GLfloat)y; - const GLfloat vertex_bottom = (GLfloat)y + glyph->height; + const GLfloat vertex_left = (x * (2.0f / surface->width)) - 1.0f; + const GLfloat vertex_right = ((x + glyph->width) * (2.0f / surface->width)) - 1.0f; + const GLfloat vertex_top = (y * (2.0f / surface->height)) - 1.0f; + const GLfloat vertex_bottom = ((y + glyph->height) * (2.0f / surface->height)) - 1.0f; glUniform4f(uniform_glyph_colour, colours[0] / 255.0f, colours[1] / 255.0f, colours[2] / 255.0f, 1.0f); @@ -553,9 +553,10 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l return; // Point our framebuffer to the destination texture - SetRenderTarget(surface); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + glViewport(0, 0, surface->width, surface->height); - DrawGlyphCommon(glyph, x, y, colours); + DrawGlyphCommon(surface, glyph, x, y, colours); } void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) @@ -564,9 +565,10 @@ void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsig return; // Point our framebuffer to the screen texture - SetRenderTarget(&framebuffer_surface); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); - DrawGlyphCommon(glyph, x, y, colours); + DrawGlyphCommon(&framebuffer_surface, glyph, x, y, colours); } void Backend_HandleDeviceLoss(void) From 74c29dbe3c4be5dd1b36005df798770392fbab64 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 06:35:32 +0000 Subject: [PATCH 055/128] Disable texture coordinates entirely when colour-filling --- src/Backends/Rendering/OpenGL2.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 99c2d4ee..7017d2d2 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -169,7 +169,6 @@ BOOL Backend_Init(SDL_Window *p_window) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(2, GL_FLOAT, 0, vertex_buffer); glTexCoordPointer(2, GL_FLOAT, 0, texture_coordinate_buffer); @@ -221,6 +220,8 @@ void Backend_DrawScreen(void) { glUseProgram(program_texture); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + // Target actual screen, and not our framebuffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); @@ -317,6 +318,8 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, Backen // Switch to colour-key shader if we have to glUseProgram(colour_key ? program_texture_colour_key : program_texture); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glBindTexture(GL_TEXTURE_2D, source_surface->texture_id); const GLfloat texture_left = (GLfloat)rect->left / (GLfloat)source_surface->width; @@ -381,6 +384,8 @@ static void ColourFillCommon(Backend_Surface *surface, const RECT *rect, unsigne glUseProgram(program_colour_fill); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glUniform4f(uniform_colour_fill_colour, red / 255.0f, green / 255.0f, blue / 255.0f, 1.0f); const GLfloat vertex_left = (rect->left * (2.0f / surface->width)) - 1.0f; @@ -517,6 +522,8 @@ static void DrawGlyphCommon(Backend_Surface *surface, Backend_Glyph *glyph, long { glUseProgram(program_glyph); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glBindTexture(GL_TEXTURE_2D, glyph->texture_id); const GLfloat vertex_left = (x * (2.0f / surface->width)) - 1.0f; From e447c9fb929e61a40203b0193ee8d4cab8d72f7e Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 06:36:13 +0000 Subject: [PATCH 056/128] Missed some matrix code --- src/Backends/Rendering/OpenGL2.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 7017d2d2..18b46bec 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -228,8 +228,6 @@ void Backend_DrawScreen(void) glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); // Draw framebuffer to screen - glLoadIdentity(); - glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id); texture_coordinate_buffer[0][0] = 0.0f; From 2c9531062bfa7e5b994718a7449d63180128d389 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 21:00:07 +0000 Subject: [PATCH 057/128] Move away from Legacy OpenGL shader variables --- src/Backends/Rendering/OpenGL2.cpp | 54 +++++++++++++++++++----------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 18b46bec..70ca22f4 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -33,8 +33,8 @@ static GLuint program_texture_colour_key; static GLuint program_colour_fill; static GLuint program_glyph; -static GLint uniform_colour_fill_colour; -static GLint uniform_glyph_colour; +static GLint program_colour_fill_uniform_colour; +static GLint program_glyph_uniform_colour; static GLuint framebuffer_id; static GLfloat vertex_buffer[4][2]; @@ -44,36 +44,42 @@ static Backend_Surface framebuffer_surface; static const GLchar *vertex_shader_plain = " \ #version 120\n \ +attribute vec2 input_vertex_coordinates; \ void main() \ { \ - gl_Position = gl_Vertex; \ + gl_Position = vec4(input_vertex_coordinates.x, input_vertex_coordinates.y, 0.0, 1.0); \ } \ "; static const GLchar *vertex_shader_texture = " \ #version 120\n \ +attribute vec2 input_vertex_coordinates; \ +attribute vec2 input_texture_coordinates; \ +varying vec2 texture_coordinates; \ void main() \ { \ - gl_TexCoord[0] = gl_MultiTexCoord0; \ - gl_Position = gl_Vertex; \ + texture_coordinates = input_texture_coordinates; \ + gl_Position = vec4(input_vertex_coordinates.x, input_vertex_coordinates.y, 0.0, 1.0); \ } \ "; static const GLchar *fragment_shader_texture = " \ #version 120\n \ uniform sampler2D tex; \ +varying vec2 texture_coordinates; \ void main() \ { \ - gl_FragColor = texture2D(tex, gl_TexCoord[0].st); \ + gl_FragColor = texture2D(tex, texture_coordinates); \ } \ "; static const GLchar *fragment_shader_texture_colour_key = " \ #version 120\n \ uniform sampler2D tex; \ +varying vec2 texture_coordinates; \ void main() \ { \ - vec4 colour = texture2D(tex, gl_TexCoord[0].st); \ + vec4 colour = texture2D(tex, texture_coordinates); \ \ if (colour.xyz == vec3(0.0f, 0.0f, 0.0f)) \ discard; \ @@ -95,9 +101,10 @@ static const GLchar *fragment_shader_glyph = " \ #version 120\n \ uniform sampler2D tex; \ uniform vec4 colour; \ +varying vec2 texture_coordinates; \ void main() \ { \ - gl_FragColor = colour * texture2D(tex, gl_TexCoord[0].st); \ + gl_FragColor = colour * texture2D(tex, texture_coordinates); \ } \ "; @@ -127,6 +134,9 @@ static GLuint CompileShader(const char *vertex_shader_source, const char *fragme glAttachShader(program_id, fragment_shader); + glBindAttribLocation(program_id, 1, "input_vertex_coordinates"); + glBindAttribLocation(program_id, 2, "input_texture_coordinates"); + glLinkProgram(program_id); glGetProgramiv(program_id, GL_LINK_STATUS, &shader_status); @@ -168,10 +178,6 @@ BOOL Backend_Init(SDL_Window *p_window) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, vertex_buffer); - glTexCoordPointer(2, GL_FLOAT, 0, texture_coordinate_buffer); - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); @@ -185,8 +191,12 @@ BOOL Backend_Init(SDL_Window *p_window) printf("Failed to compile shaders\n"); // Get shader uniforms - uniform_colour_fill_colour = glGetUniformLocation(program_colour_fill, "colour"); - uniform_glyph_colour = glGetUniformLocation(program_glyph, "colour"); + program_colour_fill_uniform_colour = glGetUniformLocation(program_colour_fill, "colour"); + program_glyph_uniform_colour = glGetUniformLocation(program_glyph, "colour"); + + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, vertex_buffer); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, texture_coordinate_buffer); // Set up framebuffer (used for surface-to-surface blitting) glGenFramebuffersEXT(1, &framebuffer_id); @@ -220,7 +230,8 @@ void Backend_DrawScreen(void) { glUseProgram(program_texture); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + // Enable texture coordinates, since this uses textures + glEnableVertexAttribArray(2); // Target actual screen, and not our framebuffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); @@ -316,7 +327,8 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, Backen // Switch to colour-key shader if we have to glUseProgram(colour_key ? program_texture_colour_key : program_texture); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + // Enable texture coordinates, since this uses textures + glEnableVertexAttribArray(2); glBindTexture(GL_TEXTURE_2D, source_surface->texture_id); @@ -382,9 +394,10 @@ static void ColourFillCommon(Backend_Surface *surface, const RECT *rect, unsigne glUseProgram(program_colour_fill); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); + // Disable texture coordinate array, since this doesn't use textures + glDisableVertexAttribArray(2); - glUniform4f(uniform_colour_fill_colour, red / 255.0f, green / 255.0f, blue / 255.0f, 1.0f); + glUniform4f(program_colour_fill_uniform_colour, red / 255.0f, green / 255.0f, blue / 255.0f, 1.0f); const GLfloat vertex_left = (rect->left * (2.0f / surface->width)) - 1.0f; const GLfloat vertex_right = (rect->right * (2.0f / surface->width)) - 1.0f; @@ -520,7 +533,8 @@ static void DrawGlyphCommon(Backend_Surface *surface, Backend_Glyph *glyph, long { glUseProgram(program_glyph); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + // Enable texture coordinates, since this uses textures + glEnableVertexAttribArray(2); glBindTexture(GL_TEXTURE_2D, glyph->texture_id); @@ -529,7 +543,7 @@ static void DrawGlyphCommon(Backend_Surface *surface, Backend_Glyph *glyph, long const GLfloat vertex_top = (y * (2.0f / surface->height)) - 1.0f; const GLfloat vertex_bottom = ((y + glyph->height) * (2.0f / surface->height)) - 1.0f; - glUniform4f(uniform_glyph_colour, colours[0] / 255.0f, colours[1] / 255.0f, colours[2] / 255.0f, 1.0f); + glUniform4f(program_glyph_uniform_colour, colours[0] / 255.0f, colours[1] / 255.0f, colours[2] / 255.0f, 1.0f); texture_coordinate_buffer[0][0] = 0.0f; texture_coordinate_buffer[0][1] = 0.0f; From 4c024b540f755ca4679f826026e4843328cccb9e Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 22:33:22 +0000 Subject: [PATCH 058/128] Migrated OpenGL backend to OpenGL 3.2 Goddammit 3.2 is so complex. The reason I want 3.2 is because I'm not convinced Legacy OpenGL will be well-supported in the future. 3.2 is about as far back as I can go without breaking forward-compatibility (it was the first version to introduce the Core Profile). --- src/Backends/Rendering/OpenGL2.cpp | 246 +++++++++++++++++------------ 1 file changed, 141 insertions(+), 105 deletions(-) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 70ca22f4..9db3c1d1 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -37,14 +37,19 @@ static GLint program_colour_fill_uniform_colour; static GLint program_glyph_uniform_colour; static GLuint framebuffer_id; -static GLfloat vertex_buffer[4][2]; -static GLfloat texture_coordinate_buffer[4][2]; +static GLuint vertex_buffer_id; + +static struct +{ + GLfloat vertexes[4][2]; + GLfloat texture_coordinates[4][2]; +} vertex_buffer; static Backend_Surface framebuffer_surface; static const GLchar *vertex_shader_plain = " \ -#version 120\n \ -attribute vec2 input_vertex_coordinates; \ +#version 150 core\n \ +in vec2 input_vertex_coordinates; \ void main() \ { \ gl_Position = vec4(input_vertex_coordinates.x, input_vertex_coordinates.y, 0.0, 1.0); \ @@ -52,10 +57,10 @@ void main() \ "; static const GLchar *vertex_shader_texture = " \ -#version 120\n \ -attribute vec2 input_vertex_coordinates; \ -attribute vec2 input_texture_coordinates; \ -varying vec2 texture_coordinates; \ +#version 150 core\n \ +in vec2 input_vertex_coordinates; \ +in vec2 input_texture_coordinates; \ +out vec2 texture_coordinates; \ void main() \ { \ texture_coordinates = input_texture_coordinates; \ @@ -64,19 +69,21 @@ void main() \ "; static const GLchar *fragment_shader_texture = " \ -#version 120\n \ +#version 150 core\n \ uniform sampler2D tex; \ -varying vec2 texture_coordinates; \ +in vec2 texture_coordinates; \ +out vec4 fragment; \ void main() \ { \ - gl_FragColor = texture2D(tex, texture_coordinates); \ + fragment = texture2D(tex, texture_coordinates); \ } \ "; static const GLchar *fragment_shader_texture_colour_key = " \ -#version 120\n \ +#version 150 core\n \ uniform sampler2D tex; \ -varying vec2 texture_coordinates; \ +in vec2 texture_coordinates; \ +out vec4 fragment; \ void main() \ { \ vec4 colour = texture2D(tex, texture_coordinates); \ @@ -84,30 +91,40 @@ void main() \ if (colour.xyz == vec3(0.0f, 0.0f, 0.0f)) \ discard; \ \ - gl_FragColor = colour; \ + fragment = colour; \ } \ "; static const GLchar *fragment_shader_colour_fill = " \ -#version 120\n \ +#version 150 core\n \ uniform vec4 colour; \ +out vec4 fragment; \ void main() \ { \ - gl_FragColor = colour; \ + fragment = colour; \ } \ "; static const GLchar *fragment_shader_glyph = " \ -#version 120\n \ +#version 150 core\n \ uniform sampler2D tex; \ uniform vec4 colour; \ -varying vec2 texture_coordinates; \ +in vec2 texture_coordinates; \ +out vec4 fragment; \ void main() \ { \ - gl_FragColor = colour * texture2D(tex, texture_coordinates); \ + fragment = colour * vec4(1.0, 1.0, 1.0, texture2D(tex, texture_coordinates).r); \ } \ "; +static void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void* userParam) +{ + if (type == GL_DEBUG_TYPE_ERROR) + printf("GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", + ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ), + type, severity, message); +} + static GLuint CompileShader(const char *vertex_shader_source, const char *fragment_shader_source) { GLint shader_status; @@ -148,9 +165,9 @@ static GLuint CompileShader(const char *vertex_shader_source, const char *fragme SDL_Window* Backend_CreateWindow(const char *title, int width, int height) { - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); } @@ -167,13 +184,13 @@ BOOL Backend_Init(SDL_Window *p_window) if (glewInit() != GLEW_OK) return FALSE; - // Check if the platform supports OpenGL 2.1 - if (!GLEW_VERSION_2_1) + // Check if the platform supports OpenGL 3.2 + if (!GLEW_VERSION_3_2) return FALSE; - // Check for framebuffer object extension (is part of the core spec in OpenGL 3.0, but not 2.1) - if (!GLEW_EXT_framebuffer_object) - return FALSE; + // During init, enable debug output + glEnable(GL_DEBUG_OUTPUT); + glDebugMessageCallback(MessageCallback, 0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -181,6 +198,23 @@ BOOL Backend_Init(SDL_Window *p_window) glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); + // Set up VAO + GLuint vertex_array_id; + glGenVertexArrays(1, &vertex_array_id); + glBindVertexArray(vertex_array_id); + + // Set up VBO + glGenBuffers(1, &vertex_buffer_id); + glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_id); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), NULL, GL_DYNAMIC_DRAW); + + // Set up IBO + const GLuint indices[4] = {0, 1, 2, 3}; + GLuint indices_buffer_id; + glGenBuffers(1, &indices_buffer_id); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer_id); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + // Set up our shaders program_texture = CompileShader(vertex_shader_texture, fragment_shader_texture); program_texture_colour_key = CompileShader(vertex_shader_texture, fragment_shader_texture_colour_key); @@ -195,12 +229,12 @@ BOOL Backend_Init(SDL_Window *p_window) program_glyph_uniform_colour = glGetUniformLocation(program_glyph, "colour"); glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, vertex_buffer); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, texture_coordinate_buffer); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(sizeof(GLfloat) * 4 * 2)); // Set up framebuffer (used for surface-to-surface blitting) - glGenFramebuffersEXT(1, &framebuffer_id); - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_id); + glGenFramebuffers(1, &framebuffer_id); + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id); // Set up framebuffer screen texture (used for screen-to-surface blitting) glGenTextures(1, &framebuffer_surface.texture_id); @@ -218,7 +252,7 @@ BOOL Backend_Init(SDL_Window *p_window) void Backend_Deinit(void) { glDeleteTextures(1, &framebuffer_surface.texture_id); - glDeleteFramebuffersEXT(1, &framebuffer_id); + glDeleteFramebuffers(1, &framebuffer_id); glDeleteProgram(program_glyph); glDeleteProgram(program_colour_fill); glDeleteProgram(program_texture_colour_key); @@ -234,32 +268,33 @@ void Backend_DrawScreen(void) glEnableVertexAttribArray(2); // Target actual screen, and not our framebuffer - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); // Draw framebuffer to screen glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id); - texture_coordinate_buffer[0][0] = 0.0f; - texture_coordinate_buffer[0][1] = 1.0f; - texture_coordinate_buffer[1][0] = 1.0f; - texture_coordinate_buffer[1][1] = 1.0f; - texture_coordinate_buffer[2][0] = 1.0f; - texture_coordinate_buffer[2][1] = 0.0f; - texture_coordinate_buffer[3][0] = 0.0f; - texture_coordinate_buffer[3][1] = 0.0f; + vertex_buffer.texture_coordinates[0][0] = 0.0f; + vertex_buffer.texture_coordinates[0][1] = 1.0f; + vertex_buffer.texture_coordinates[1][0] = 1.0f; + vertex_buffer.texture_coordinates[1][1] = 1.0f; + vertex_buffer.texture_coordinates[2][0] = 1.0f; + vertex_buffer.texture_coordinates[2][1] = 0.0f; + vertex_buffer.texture_coordinates[3][0] = 0.0f; + vertex_buffer.texture_coordinates[3][1] = 0.0f; - vertex_buffer[0][0] = -1.0f; - vertex_buffer[0][1] = -1.0f; - vertex_buffer[1][0] = 1.0f; - vertex_buffer[1][1] = -1.0f; - vertex_buffer[2][0] = 1.0f; - vertex_buffer[2][1] = 1.0f; - vertex_buffer[3][0] = -1.0f; - vertex_buffer[3][1] = 1.0f; + vertex_buffer.vertexes[0][0] = -1.0f; + vertex_buffer.vertexes[0][1] = -1.0f; + vertex_buffer.vertexes[1][0] = 1.0f; + vertex_buffer.vertexes[1][1] = -1.0f; + vertex_buffer.vertexes[2][0] = 1.0f; + vertex_buffer.vertexes[2][1] = 1.0f; + vertex_buffer.vertexes[3][0] = -1.0f; + vertex_buffer.vertexes[3][1] = 1.0f; - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, NULL); SDL_GL_SwapWindow(window); @@ -268,7 +303,7 @@ void Backend_DrawScreen(void) glClear(GL_COLOR_BUFFER_BIT); // Switch back to our framebuffer - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_id); + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id); } Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) @@ -342,25 +377,26 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, Backen const GLfloat vertex_top = (y * (2.0f / destination_surface->height)) - 1.0f; const GLfloat vertex_bottom = ((y + (rect->bottom - rect->top)) * (2.0f / destination_surface->height)) - 1.0f; - texture_coordinate_buffer[0][0] = texture_left; - texture_coordinate_buffer[0][1] = texture_top; - texture_coordinate_buffer[1][0] = texture_right; - texture_coordinate_buffer[1][1] = texture_top; - texture_coordinate_buffer[2][0] = texture_right; - texture_coordinate_buffer[2][1] = texture_bottom; - texture_coordinate_buffer[3][0] = texture_left; - texture_coordinate_buffer[3][1] = texture_bottom; + vertex_buffer.texture_coordinates[0][0] = texture_left; + vertex_buffer.texture_coordinates[0][1] = texture_top; + vertex_buffer.texture_coordinates[1][0] = texture_right; + vertex_buffer.texture_coordinates[1][1] = texture_top; + vertex_buffer.texture_coordinates[2][0] = texture_right; + vertex_buffer.texture_coordinates[2][1] = texture_bottom; + vertex_buffer.texture_coordinates[3][0] = texture_left; + vertex_buffer.texture_coordinates[3][1] = texture_bottom; - vertex_buffer[0][0] = vertex_left; - vertex_buffer[0][1] = vertex_top; - vertex_buffer[1][0] = vertex_right; - vertex_buffer[1][1] = vertex_top; - vertex_buffer[2][0] = vertex_right; - vertex_buffer[2][1] = vertex_bottom; - vertex_buffer[3][0] = vertex_left; - vertex_buffer[3][1] = vertex_bottom; + vertex_buffer.vertexes[0][0] = vertex_left; + vertex_buffer.vertexes[0][1] = vertex_top; + vertex_buffer.vertexes[1][0] = vertex_right; + vertex_buffer.vertexes[1][1] = vertex_top; + vertex_buffer.vertexes[2][0] = vertex_right; + vertex_buffer.vertexes[2][1] = vertex_bottom; + vertex_buffer.vertexes[3][0] = vertex_left; + vertex_buffer.vertexes[3][1] = vertex_bottom; - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, NULL); } void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) @@ -369,7 +405,7 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur return; // Point our framebuffer to the destination texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, destination_surface->texture_id, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destination_surface->texture_id, 0); glViewport(0, 0, destination_surface->width, destination_surface->height); BlitCommon(source_surface, rect, destination_surface, x, y, colour_key); @@ -381,7 +417,7 @@ void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, lon return; // Point our framebuffer to the screen texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); BlitCommon(source_surface, rect, &framebuffer_surface, x, y, colour_key); @@ -404,16 +440,17 @@ static void ColourFillCommon(Backend_Surface *surface, const RECT *rect, unsigne const GLfloat vertex_top = (rect->top * (2.0f / surface->height)) - 1.0f; const GLfloat vertex_bottom = (rect->bottom * (2.0f / surface->height)) - 1.0f; - vertex_buffer[0][0] = vertex_left; - vertex_buffer[0][1] = vertex_top; - vertex_buffer[1][0] = vertex_right; - vertex_buffer[1][1] = vertex_top; - vertex_buffer[2][0] = vertex_right; - vertex_buffer[2][1] = vertex_bottom; - vertex_buffer[3][0] = vertex_left; - vertex_buffer[3][1] = vertex_bottom; + vertex_buffer.vertexes[0][0] = vertex_left; + vertex_buffer.vertexes[0][1] = vertex_top; + vertex_buffer.vertexes[1][0] = vertex_right; + vertex_buffer.vertexes[1][1] = vertex_top; + vertex_buffer.vertexes[2][0] = vertex_right; + vertex_buffer.vertexes[2][1] = vertex_bottom; + vertex_buffer.vertexes[3][0] = vertex_left; + vertex_buffer.vertexes[3][1] = vertex_bottom; - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, NULL); } void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) @@ -422,7 +459,7 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha return; // Point our framebuffer to the destination texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, surface->texture_id, 0); glViewport(0, 0, surface->width, surface->height); ColourFillCommon(surface, rect, red, green, blue); @@ -431,7 +468,7 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { // Point our framebuffer to the screen texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); ColourFillCommon(&framebuffer_surface, rect, red, green, blue); @@ -443,7 +480,7 @@ void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) return; // Point our framebuffer to the destination texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, surface->texture_id, 0); glViewport(0, 0, surface->width, surface->height); BlitCommon(&framebuffer_surface, rect, surface, rect->left, rect->top, FALSE); @@ -461,7 +498,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width if (glyph == NULL) return NULL; - const int destination_pitch = ((width * 2) + 3) & ~3; // Round up to the nearest 4 (OpenGL needs this) + const int destination_pitch = (width + 3) & ~3; // Round up to the nearest 4 (OpenGL needs this) unsigned char *buffer = (unsigned char*)malloc(destination_pitch * height); @@ -483,7 +520,6 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width for (unsigned int x = 0; x < width; ++x) { - *destination_pointer++ = 0xFF; *destination_pointer++ = (unsigned char)(pow((double)*source_pointer++ / (total_greys - 1), 1.0 / 1.8) * 255.0); } } @@ -498,7 +534,6 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width for (unsigned int x = 0; x < width; ++x) { - *destination_pointer++ = 0xFF; *destination_pointer++ = *source_pointer++ ? 0xFF : 0; } } @@ -508,7 +543,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width glGenTextures(1, &glyph->texture_id); glBindTexture(GL_TEXTURE_2D, glyph->texture_id); - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE8_ALPHA8, width, height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, buffer); + glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, buffer); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -545,25 +580,26 @@ static void DrawGlyphCommon(Backend_Surface *surface, Backend_Glyph *glyph, long glUniform4f(program_glyph_uniform_colour, colours[0] / 255.0f, colours[1] / 255.0f, colours[2] / 255.0f, 1.0f); - texture_coordinate_buffer[0][0] = 0.0f; - texture_coordinate_buffer[0][1] = 0.0f; - texture_coordinate_buffer[1][0] = 1.0f; - texture_coordinate_buffer[1][1] = 0.0f; - texture_coordinate_buffer[2][0] = 1.0f; - texture_coordinate_buffer[2][1] = 1.0f; - texture_coordinate_buffer[3][0] = 0.0f; - texture_coordinate_buffer[3][1] = 1.0f; + vertex_buffer.texture_coordinates[0][0] = 0.0f; + vertex_buffer.texture_coordinates[0][1] = 0.0f; + vertex_buffer.texture_coordinates[1][0] = 1.0f; + vertex_buffer.texture_coordinates[1][1] = 0.0f; + vertex_buffer.texture_coordinates[2][0] = 1.0f; + vertex_buffer.texture_coordinates[2][1] = 1.0f; + vertex_buffer.texture_coordinates[3][0] = 0.0f; + vertex_buffer.texture_coordinates[3][1] = 1.0f; - vertex_buffer[0][0] = vertex_left; - vertex_buffer[0][1] = vertex_top; - vertex_buffer[1][0] = vertex_right; - vertex_buffer[1][1] = vertex_top; - vertex_buffer[2][0] = vertex_right; - vertex_buffer[2][1] = vertex_bottom; - vertex_buffer[3][0] = vertex_left; - vertex_buffer[3][1] = vertex_bottom; + vertex_buffer.vertexes[0][0] = vertex_left; + vertex_buffer.vertexes[0][1] = vertex_top; + vertex_buffer.vertexes[1][0] = vertex_right; + vertex_buffer.vertexes[1][1] = vertex_top; + vertex_buffer.vertexes[2][0] = vertex_right; + vertex_buffer.vertexes[2][1] = vertex_bottom; + vertex_buffer.vertexes[3][0] = vertex_left; + vertex_buffer.vertexes[3][1] = vertex_bottom; - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, NULL); } void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) @@ -572,7 +608,7 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l return; // Point our framebuffer to the destination texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, surface->texture_id, 0); glViewport(0, 0, surface->width, surface->height); DrawGlyphCommon(surface, glyph, x, y, colours); @@ -584,7 +620,7 @@ void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsig return; // Point our framebuffer to the screen texture - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); DrawGlyphCommon(&framebuffer_surface, glyph, x, y, colours); From eb62a80956b485c780f9028cd08440b4971aecba Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 22:38:33 +0000 Subject: [PATCH 059/128] Change references to OpenGL 2.1 to 3.2 --- CMakeLists.txt | 6 +++--- Makefile | 4 ++-- README.md | 4 ++-- src/Backends/Rendering/{OpenGL2.cpp => OpenGL3.cpp} | 0 4 files changed, 7 insertions(+), 7 deletions(-) rename src/Backends/Rendering/{OpenGL2.cpp => OpenGL3.cpp} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb2ff037..609b3a12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ option(JAPANESE "Enable the Japanese-language build" OFF) option(FIX_BUGS "Fix certain bugs (see src/Bug Fixes.txt)" OFF) option(NONPORTABLE "Enable bits of code that aren't portable, but are what the original game used" OFF) option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF) -set(RENDERER "Texture" CACHE STRING "Which renderer the game should use: 'OpenGL2' for an OpenGL 2.1 renderer, 'Texture' for SDL2's hardware-accelerated Texture API, 'Surface' for SDL2's software-rendered Surface API, and 'Software' for a handwritten software renderer") +set(RENDERER "Texture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.2 renderer, 'Texture' for SDL2's hardware-accelerated Texture API, 'Surface' for SDL2's software-rendered Surface API, and 'Software' for a handwritten software renderer") project(CSE2 LANGUAGES C CXX) @@ -246,8 +246,8 @@ if(NONPORTABLE) target_compile_definitions(CSE2 PRIVATE NONPORTABLE) endif() -if(RENDERER MATCHES "OpenGL2") - target_sources(CSE2 PRIVATE "src/Backends/Rendering/OpenGL2.cpp") +if(RENDERER MATCHES "OpenGL3") + target_sources(CSE2 PRIVATE "src/Backends/Rendering/OpenGL3.cpp") find_package(GLEW REQUIRED) target_link_libraries(CSE2 GLEW::GLEW) find_package(OpenGL REQUIRED) diff --git a/Makefile b/Makefile index e465804c..64acea61 100644 --- a/Makefile +++ b/Makefile @@ -208,8 +208,8 @@ ifneq ($(WINDOWS), 1) RESOURCES += ICON/ICON_MINI.bmp endif -ifeq ($(RENDERER), OpenGL2) - SOURCES += Backends/Rendering/OpenGL2 +ifeq ($(RENDERER), OpenGL3) + SOURCES += Backends/Rendering/OpenGL3 CXXFLAGS += `pkg-config glew --cflags` ifeq ($(STATIC), 1) diff --git a/README.md b/README.md index 2ef20f75..d9198892 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ You can also add the following flags: * `-DFIX_BUGS=ON` - Fix bugs in the game (see [src/Bug Fixes.txt](src/Bug%20Fixes.txt)) * `-DNONPORTABLE=ON` - Enable bits of code that aren't portable, but are what the original game used * `-DFORCE_LOCAL_LIBS=ON` - Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones -* `-DRENDERER=OpenGL2` - Use the hardware-accelerated OpenGL 2.1 renderer +* `-DRENDERER=OpenGL3` - Use the hardware-accelerated OpenGL 3.2 renderer * `-DRENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default) * `-DRENDERER=Surface` - Use the software-rendered SDL2 Surface API renderer * `-DRENDERER=Software` - Use a handwritten software renderer @@ -58,7 +58,7 @@ Run 'make' in this folder, preferably with some of the following settings: * `WINDOWS=1` - Enable Windows-only features like a unique file/taskbar icon, and system font loading (needed for the font setting in Config.dat to do anything) * `RASPBERRY_PI=1` - Enable tweaks to improve performance on Raspberry Pis * `NONPORTABLE=1` - Enable bits of code that aren't portable, but are what the original game used -* `RENDERER=OpenGL2` - Use the hardware-accelerated OpenGL 2.1 renderer +* `RENDERER=OpenGL3` - Use the hardware-accelerated OpenGL 3.2 renderer * `RENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default) * `RENDERER=Surface` - Use the software-rendered SDL2 Surface API renderer * `RENDERER=Software` - Use a hand-written software renderer diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL3.cpp similarity index 100% rename from src/Backends/Rendering/OpenGL2.cpp rename to src/Backends/Rendering/OpenGL3.cpp From 350ba46f2e9e3f13c8a9a22c2248f4d8aa0d732c Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 22:48:37 +0000 Subject: [PATCH 060/128] Some OpenGL cleanup --- src/Backends/Rendering/OpenGL3.cpp | 33 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 9db3c1d1..eee941da 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -25,6 +25,12 @@ typedef struct Backend_Glyph unsigned int height; } Backend_Glyph; +typedef struct VertexBuffer +{ + GLfloat vertexes[4][2]; + GLfloat texture_coordinates[4][2]; +} VertexBuffer; + static SDL_Window *window; static SDL_GLContext context; @@ -39,11 +45,7 @@ static GLint program_glyph_uniform_colour; static GLuint framebuffer_id; static GLuint vertex_buffer_id; -static struct -{ - GLfloat vertexes[4][2]; - GLfloat texture_coordinates[4][2]; -} vertex_buffer; +static VertexBuffer vertex_buffer; static Backend_Surface framebuffer_surface; @@ -198,23 +200,28 @@ BOOL Backend_Init(SDL_Window *p_window) glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); - // Set up VAO + // Set up Vertex Array Object GLuint vertex_array_id; glGenVertexArrays(1, &vertex_array_id); glBindVertexArray(vertex_array_id); - // Set up VBO + // Set up Vertex Buffer Object glGenBuffers(1, &vertex_buffer_id); glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_id); glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), NULL, GL_DYNAMIC_DRAW); - // Set up IBO + // Set up Index Buffer Object const GLuint indices[4] = {0, 1, 2, 3}; - GLuint indices_buffer_id; - glGenBuffers(1, &indices_buffer_id); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer_id); + GLuint index_buffer_id; + glGenBuffers(1, &index_buffer_id); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer_id); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + // Set up the vertex attributes + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)offsetof(VertexBuffer, vertexes)); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)offsetof(VertexBuffer, texture_coordinates)); + // Set up our shaders program_texture = CompileShader(vertex_shader_texture, fragment_shader_texture); program_texture_colour_key = CompileShader(vertex_shader_texture, fragment_shader_texture_colour_key); @@ -228,10 +235,6 @@ BOOL Backend_Init(SDL_Window *p_window) program_colour_fill_uniform_colour = glGetUniformLocation(program_colour_fill, "colour"); program_glyph_uniform_colour = glGetUniformLocation(program_glyph, "colour"); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(sizeof(GLfloat) * 4 * 2)); - // Set up framebuffer (used for surface-to-surface blitting) glGenFramebuffers(1, &framebuffer_id); glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id); From ff5a0189e096e029acf107b9a1268f1791221bc7 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 22:50:14 +0000 Subject: [PATCH 061/128] OpenGL: Ditch index buffer Seems completely unnecessary for 2D --- src/Backends/Rendering/OpenGL3.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index eee941da..be0263dc 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -210,13 +210,6 @@ BOOL Backend_Init(SDL_Window *p_window) glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_id); glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), NULL, GL_DYNAMIC_DRAW); - // Set up Index Buffer Object - const GLuint indices[4] = {0, 1, 2, 3}; - GLuint index_buffer_id; - glGenBuffers(1, &index_buffer_id); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer_id); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); - // Set up the vertex attributes glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)offsetof(VertexBuffer, vertexes)); @@ -297,7 +290,7 @@ void Backend_DrawScreen(void) vertex_buffer.vertexes[3][1] = 1.0f; glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); - glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, NULL); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); SDL_GL_SwapWindow(window); @@ -399,7 +392,7 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, Backen vertex_buffer.vertexes[3][1] = vertex_bottom; glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); - glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, NULL); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) @@ -453,7 +446,7 @@ static void ColourFillCommon(Backend_Surface *surface, const RECT *rect, unsigne vertex_buffer.vertexes[3][1] = vertex_bottom; glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); - glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, NULL); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) @@ -602,7 +595,7 @@ static void DrawGlyphCommon(Backend_Surface *surface, Backend_Glyph *glyph, long vertex_buffer.vertexes[3][1] = vertex_bottom; glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); - glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, NULL); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) From 24dcd35522a7bbc2bd419e91c7672a1fb53118b7 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 23:01:14 +0000 Subject: [PATCH 062/128] More OpenGL cleanup and tweaks --- src/Backends/Rendering/OpenGL3.cpp | 55 +++++++++--------------------- 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index be0263dc..7407a792 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -122,9 +122,7 @@ void main() \ static void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void* userParam) { if (type == GL_DEBUG_TYPE_ERROR) - printf("GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", - ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ), - type, severity, message); + printf("GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ), type, severity, message); } static GLuint CompileShader(const char *vertex_shader_source, const char *fragment_shader_source) @@ -190,7 +188,6 @@ BOOL Backend_Init(SDL_Window *p_window) if (!GLEW_VERSION_3_2) return FALSE; - // During init, enable debug output glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallback(MessageCallback, 0); @@ -295,7 +292,7 @@ void Backend_DrawScreen(void) SDL_GL_SwapWindow(window); // According to https://www.khronos.org/opengl/wiki/Common_Mistakes#Swap_Buffers - // the buffer should always be cleared + // the buffer should always be cleared, even if it seems unnecessary glClear(GL_COLOR_BUFFER_BIT); // Switch back to our framebuffer @@ -352,9 +349,16 @@ void Backend_Unlock(Backend_Surface *surface) static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) { + if (source_surface == NULL || destination_surface == NULL) + return; + if (rect->right - rect->left < 0 || rect->bottom - rect->top < 0) return; + // Point our framebuffer to the destination texture + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destination_surface->texture_id, 0); + glViewport(0, 0, destination_surface->width, destination_surface->height); + // Switch to colour-key shader if we have to glUseProgram(colour_key ? program_texture_colour_key : program_texture); @@ -397,33 +401,26 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, Backen void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) { - if (source_surface == NULL || destination_surface == NULL) - return; - - // Point our framebuffer to the destination texture - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destination_surface->texture_id, 0); - glViewport(0, 0, destination_surface->width, destination_surface->height); - BlitCommon(source_surface, rect, destination_surface, x, y, colour_key); } void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) { - if (source_surface == NULL) - return; - - // Point our framebuffer to the screen texture - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); - glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); - BlitCommon(source_surface, rect, &framebuffer_surface, x, y, colour_key); } static void ColourFillCommon(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { + if (surface == NULL) + return; + if (rect->right - rect->left < 0 || rect->bottom - rect->top < 0) return; + // Point our framebuffer to the destination texture + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, surface->texture_id, 0); + glViewport(0, 0, surface->width, surface->height); + glUseProgram(program_colour_fill); // Disable texture coordinate array, since this doesn't use textures @@ -445,40 +442,22 @@ static void ColourFillCommon(Backend_Surface *surface, const RECT *rect, unsigne vertex_buffer.vertexes[3][0] = vertex_left; vertex_buffer.vertexes[3][1] = vertex_bottom; - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer.vertexes), &vertex_buffer); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { - if (surface == NULL) - return; - - // Point our framebuffer to the destination texture - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, surface->texture_id, 0); - glViewport(0, 0, surface->width, surface->height); - ColourFillCommon(surface, rect, red, green, blue); } void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { - // Point our framebuffer to the screen texture - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); - glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); - ColourFillCommon(&framebuffer_surface, rect, red, green, blue); } void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) { - if (surface == NULL) - return; - - // Point our framebuffer to the destination texture - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, surface->texture_id, 0); - glViewport(0, 0, surface->width, surface->height); - BlitCommon(&framebuffer_surface, rect, surface, rect->left, rect->top, FALSE); } From 4769397c7ac45c074e88208dcefd585c7c8f3c63 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 23:03:32 +0000 Subject: [PATCH 063/128] Clean up OpenGL error callback print --- src/Backends/Rendering/OpenGL3.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 7407a792..0bd69e9e 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -121,8 +121,14 @@ void main() \ static void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void* userParam) { + (void)source; + (void)id; + (void)severity; + (void)length; + (void)userParam; + if (type == GL_DEBUG_TYPE_ERROR) - printf("GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ), type, severity, message); + printf("OpenGL error: %s\n", message); } static GLuint CompileShader(const char *vertex_shader_source, const char *fragment_shader_source) From 90ffbacd29a110fb0627202abca5e5a1dafd43ec Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 23:07:45 +0000 Subject: [PATCH 064/128] Put OpenGL in 'forward-compatible' mode Disables deprecated functionality --- src/Backends/Rendering/OpenGL3.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 0bd69e9e..af5d5847 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -172,6 +172,7 @@ static GLuint CompileShader(const char *vertex_shader_source, const char *fragme SDL_Window* Backend_CreateWindow(const char *title, int width, int height) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); From 607bbfcef85c488dfefef1ce30a3e614b4adb6e1 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 23:12:06 +0000 Subject: [PATCH 065/128] Remove some debug prints I prefer to only print on error --- src/Draw.cpp | 4 ---- src/Organya.cpp | 1 - 2 files changed, 5 deletions(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index 23913f3c..040c9e24 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -260,7 +260,6 @@ static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface) Backend_Unlock(surf[surf_no].backend); SDL_FreeSurface(converted_surface); - printf(" ^ Successfully loaded\n"); success = TRUE; } } @@ -292,7 +291,6 @@ static BOOL LoadBitmap_File(const char *name, Surface_Ids surf_no, BOOL create_s } else { - printf("Loading surface (as .pbm) from %s for surface id %d\n", path, surf_no); if (LoadBitmap(fp, surf_no, create_surface)) return TRUE; } @@ -303,7 +301,6 @@ static BOOL LoadBitmap_File(const char *name, Surface_Ids surf_no, BOOL create_s fp = SDL_RWFromFile(path, "rb"); if (fp) { - printf("Loading surface (as .bmp) from %s for surface id %d\n", path, surf_no); if (LoadBitmap(fp, surf_no, create_surface)) return TRUE; } @@ -324,7 +321,6 @@ static BOOL LoadBitmap_Resource(const char *res, Surface_Ids surf_no, BOOL creat // But hey, if I ever need to create an RWops from an array that's -32768 bytes long, they've got me covered! SDL_RWops *fp = SDL_RWFromConstMem(data, size); - printf("Loading surface from resource %s for surface id %d\n", res, surf_no); if (LoadBitmap(fp, surf_no, create_surface)) return TRUE; } diff --git a/src/Organya.cpp b/src/Organya.cpp index 3de9f757..e8305421 100644 --- a/src/Organya.cpp +++ b/src/Organya.cpp @@ -432,7 +432,6 @@ void LoadOrganya(const char *name) memset(now_leng, 0, sizeof(now_leng)); // Open file - printf("Loading org %s\n", name); const unsigned char *p = FindResource(name, "ORG", NULL); // Version Check From 706aff0c8c9f6c518b88cb8d1ca875a0e7d05544 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 31 Jul 2019 23:43:08 +0000 Subject: [PATCH 066/128] Remove more redundant OpenGL code --- src/Backends/Rendering/OpenGL3.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index af5d5847..81c870f7 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -548,6 +548,13 @@ void Backend_UnloadGlyph(Backend_Glyph *glyph) static void DrawGlyphCommon(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { + if (glyph == NULL || surface == NULL) + return; + + // Point our framebuffer to the destination texture + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, surface->texture_id, 0); + glViewport(0, 0, surface->width, surface->height); + glUseProgram(program_glyph); // Enable texture coordinates, since this uses textures @@ -586,25 +593,11 @@ static void DrawGlyphCommon(Backend_Surface *surface, Backend_Glyph *glyph, long void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { - if (glyph == NULL || surface == NULL) - return; - - // Point our framebuffer to the destination texture - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, surface->texture_id, 0); - glViewport(0, 0, surface->width, surface->height); - DrawGlyphCommon(surface, glyph, x, y, colours); } void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) { - if (glyph == NULL) - return; - - // Point our framebuffer to the screen texture - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0); - glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height); - DrawGlyphCommon(&framebuffer_surface, glyph, x, y, colours); } From f0c062cdc8bbe89450466caec89d7efffae91641 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 1 Aug 2019 00:08:23 +0000 Subject: [PATCH 067/128] OpenGL: Clamp textures This fixes this weird thing you'd see in the enhanced branch if the screen is scaled (happens if you resize the window). When the screen is scaled, OpenGL uses linear interpolation. This would cause it to fetch samples from outside the texture. IIRC, by default, the default behaviour is GL_REPEAT, which causes it to blend with samples from the other side of the texture, creating strange pixels at the end of the screen. --- src/Backends/Rendering/OpenGL3.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 81c870f7..73f666ff 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -242,6 +242,9 @@ BOOL Backend_Init(SDL_Window *p_window) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, window_width, window_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); framebuffer_surface.width = window_width; framebuffer_surface.height = window_height; @@ -318,6 +321,9 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); surface->width = width; surface->height = height; @@ -528,6 +534,9 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, buffer); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glyph->width = width; glyph->height = height; From d8d971c45953462282f5cdd6ececc2f90127ae7c Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 1 Aug 2019 00:34:35 +0000 Subject: [PATCH 068/128] Added another bugfix --- src/TextScr.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/TextScr.cpp b/src/TextScr.cpp index c6135890..02fecfc5 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -464,7 +464,14 @@ void PutTextScript() if (gTS.face_x < (TEXT_LEFT * 0x200)) gTS.face_x += 0x1000; +#ifdef FIX_BUGS + gTS.rcText.top -= 2; + PutBitmap3(&gTS.rcText, gTS.face_x / 0x200, gTS.rcText.top, &rcFace, SURFACE_ID_FACE); + gTS.rcText.top += 2; +#else + // The top few rows of pixels are cut off by the clip rectangle, and the facepic is off-centre PutBitmap3(&gTS.rcText, gTS.face_x / 0x200, gTS.rcText.top - 3, &rcFace, SURFACE_ID_FACE); +#endif //Draw text if (gTS.face) From cf94736cbfb03e63753c60d0fd55fd8c6b90dddf Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 1 Aug 2019 00:38:23 +0000 Subject: [PATCH 069/128] OpenGL: Free VAO and VBO --- src/Backends/Rendering/OpenGL3.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 73f666ff..69e0e3fe 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -42,8 +42,9 @@ static GLuint program_glyph; static GLint program_colour_fill_uniform_colour; static GLint program_glyph_uniform_colour; -static GLuint framebuffer_id; +static GLuint vertex_array_id; static GLuint vertex_buffer_id; +static GLuint framebuffer_id; static VertexBuffer vertex_buffer; @@ -205,7 +206,6 @@ BOOL Backend_Init(SDL_Window *p_window) glClear(GL_COLOR_BUFFER_BIT); // Set up Vertex Array Object - GLuint vertex_array_id; glGenVertexArrays(1, &vertex_array_id); glBindVertexArray(vertex_array_id); @@ -260,6 +260,8 @@ void Backend_Deinit(void) glDeleteProgram(program_colour_fill); glDeleteProgram(program_texture_colour_key); glDeleteProgram(program_texture); + glDeleteBuffers(1, &vertex_buffer_id); + glDeleteVertexArrays(1, &vertex_array_id); SDL_GL_DeleteContext(context); } From 67b3143ed6269a281541381e9ef6dfb3289de853 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 1 Aug 2019 01:26:04 +0000 Subject: [PATCH 070/128] OpenGL: Only enable blending for glyphs Should improve performance --- src/Backends/Rendering/OpenGL3.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 69e0e3fe..40caaf8d 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -199,7 +199,6 @@ BOOL Backend_Init(SDL_Window *p_window) glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallback(MessageCallback, 0); - glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); @@ -269,6 +268,8 @@ void Backend_DrawScreen(void) { glUseProgram(program_texture); + glDisable(GL_BLEND); + // Enable texture coordinates, since this uses textures glEnableVertexAttribArray(2); @@ -377,6 +378,8 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, Backen // Switch to colour-key shader if we have to glUseProgram(colour_key ? program_texture_colour_key : program_texture); + glDisable(GL_BLEND); + // Enable texture coordinates, since this uses textures glEnableVertexAttribArray(2); @@ -438,6 +441,8 @@ static void ColourFillCommon(Backend_Surface *surface, const RECT *rect, unsigne glUseProgram(program_colour_fill); + glDisable(GL_BLEND); + // Disable texture coordinate array, since this doesn't use textures glDisableVertexAttribArray(2); @@ -568,6 +573,8 @@ static void DrawGlyphCommon(Backend_Surface *surface, Backend_Glyph *glyph, long glUseProgram(program_glyph); + glEnable(GL_BLEND); + // Enable texture coordinates, since this uses textures glEnableVertexAttribArray(2); From d8aec418f9a72e51897a5256cdd78ee56e9053d0 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 1 Aug 2019 13:11:55 +0000 Subject: [PATCH 071/128] OpenGL: Use a struct for defining 2D coordinates Makes the code a bit more readable --- src/Backends/Rendering/OpenGL3.cpp | 122 +++++++++++++++-------------- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 40caaf8d..9e2209c3 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -25,10 +25,16 @@ typedef struct Backend_Glyph unsigned int height; } Backend_Glyph; +typedef struct Coordinate2D +{ + GLfloat x; + GLfloat y; +} Coordinate2D; + typedef struct VertexBuffer { - GLfloat vertexes[4][2]; - GLfloat texture_coordinates[4][2]; + Coordinate2D vertexes[4]; + Coordinate2D texture_coordinates[4]; } VertexBuffer; static SDL_Window *window; @@ -281,23 +287,23 @@ void Backend_DrawScreen(void) // Draw framebuffer to screen glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id); - vertex_buffer.texture_coordinates[0][0] = 0.0f; - vertex_buffer.texture_coordinates[0][1] = 1.0f; - vertex_buffer.texture_coordinates[1][0] = 1.0f; - vertex_buffer.texture_coordinates[1][1] = 1.0f; - vertex_buffer.texture_coordinates[2][0] = 1.0f; - vertex_buffer.texture_coordinates[2][1] = 0.0f; - vertex_buffer.texture_coordinates[3][0] = 0.0f; - vertex_buffer.texture_coordinates[3][1] = 0.0f; + vertex_buffer.texture_coordinates[0].x = 0.0f; + vertex_buffer.texture_coordinates[0].y = 1.0f; + vertex_buffer.texture_coordinates[1].x = 1.0f; + vertex_buffer.texture_coordinates[1].y = 1.0f; + vertex_buffer.texture_coordinates[2].x = 1.0f; + vertex_buffer.texture_coordinates[2].y = 0.0f; + vertex_buffer.texture_coordinates[3].x = 0.0f; + vertex_buffer.texture_coordinates[3].y = 0.0f; - vertex_buffer.vertexes[0][0] = -1.0f; - vertex_buffer.vertexes[0][1] = -1.0f; - vertex_buffer.vertexes[1][0] = 1.0f; - vertex_buffer.vertexes[1][1] = -1.0f; - vertex_buffer.vertexes[2][0] = 1.0f; - vertex_buffer.vertexes[2][1] = 1.0f; - vertex_buffer.vertexes[3][0] = -1.0f; - vertex_buffer.vertexes[3][1] = 1.0f; + vertex_buffer.vertexes[0].x = -1.0f; + vertex_buffer.vertexes[0].y = -1.0f; + vertex_buffer.vertexes[1].x = 1.0f; + vertex_buffer.vertexes[1].y = -1.0f; + vertex_buffer.vertexes[2].x = 1.0f; + vertex_buffer.vertexes[2].y = 1.0f; + vertex_buffer.vertexes[3].x = -1.0f; + vertex_buffer.vertexes[3].y = 1.0f; glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -395,23 +401,23 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, Backen const GLfloat vertex_top = (y * (2.0f / destination_surface->height)) - 1.0f; const GLfloat vertex_bottom = ((y + (rect->bottom - rect->top)) * (2.0f / destination_surface->height)) - 1.0f; - vertex_buffer.texture_coordinates[0][0] = texture_left; - vertex_buffer.texture_coordinates[0][1] = texture_top; - vertex_buffer.texture_coordinates[1][0] = texture_right; - vertex_buffer.texture_coordinates[1][1] = texture_top; - vertex_buffer.texture_coordinates[2][0] = texture_right; - vertex_buffer.texture_coordinates[2][1] = texture_bottom; - vertex_buffer.texture_coordinates[3][0] = texture_left; - vertex_buffer.texture_coordinates[3][1] = texture_bottom; + vertex_buffer.texture_coordinates[0].x = texture_left; + vertex_buffer.texture_coordinates[0].y = texture_top; + vertex_buffer.texture_coordinates[1].x = texture_right; + vertex_buffer.texture_coordinates[1].y = texture_top; + vertex_buffer.texture_coordinates[2].x = texture_right; + vertex_buffer.texture_coordinates[2].y = texture_bottom; + vertex_buffer.texture_coordinates[3].x = texture_left; + vertex_buffer.texture_coordinates[3].y = texture_bottom; - vertex_buffer.vertexes[0][0] = vertex_left; - vertex_buffer.vertexes[0][1] = vertex_top; - vertex_buffer.vertexes[1][0] = vertex_right; - vertex_buffer.vertexes[1][1] = vertex_top; - vertex_buffer.vertexes[2][0] = vertex_right; - vertex_buffer.vertexes[2][1] = vertex_bottom; - vertex_buffer.vertexes[3][0] = vertex_left; - vertex_buffer.vertexes[3][1] = vertex_bottom; + vertex_buffer.vertexes[0].x = vertex_left; + vertex_buffer.vertexes[0].y = vertex_top; + vertex_buffer.vertexes[1].x = vertex_right; + vertex_buffer.vertexes[1].y = vertex_top; + vertex_buffer.vertexes[2].x = vertex_right; + vertex_buffer.vertexes[2].y = vertex_bottom; + vertex_buffer.vertexes[3].x = vertex_left; + vertex_buffer.vertexes[3].y = vertex_bottom; glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -453,14 +459,14 @@ static void ColourFillCommon(Backend_Surface *surface, const RECT *rect, unsigne const GLfloat vertex_top = (rect->top * (2.0f / surface->height)) - 1.0f; const GLfloat vertex_bottom = (rect->bottom * (2.0f / surface->height)) - 1.0f; - vertex_buffer.vertexes[0][0] = vertex_left; - vertex_buffer.vertexes[0][1] = vertex_top; - vertex_buffer.vertexes[1][0] = vertex_right; - vertex_buffer.vertexes[1][1] = vertex_top; - vertex_buffer.vertexes[2][0] = vertex_right; - vertex_buffer.vertexes[2][1] = vertex_bottom; - vertex_buffer.vertexes[3][0] = vertex_left; - vertex_buffer.vertexes[3][1] = vertex_bottom; + vertex_buffer.vertexes[0].x = vertex_left; + vertex_buffer.vertexes[0].y = vertex_top; + vertex_buffer.vertexes[1].x = vertex_right; + vertex_buffer.vertexes[1].y = vertex_top; + vertex_buffer.vertexes[2].x = vertex_right; + vertex_buffer.vertexes[2].y = vertex_bottom; + vertex_buffer.vertexes[3].x = vertex_left; + vertex_buffer.vertexes[3].y = vertex_bottom; glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer.vertexes), &vertex_buffer); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -587,23 +593,23 @@ static void DrawGlyphCommon(Backend_Surface *surface, Backend_Glyph *glyph, long glUniform4f(program_glyph_uniform_colour, colours[0] / 255.0f, colours[1] / 255.0f, colours[2] / 255.0f, 1.0f); - vertex_buffer.texture_coordinates[0][0] = 0.0f; - vertex_buffer.texture_coordinates[0][1] = 0.0f; - vertex_buffer.texture_coordinates[1][0] = 1.0f; - vertex_buffer.texture_coordinates[1][1] = 0.0f; - vertex_buffer.texture_coordinates[2][0] = 1.0f; - vertex_buffer.texture_coordinates[2][1] = 1.0f; - vertex_buffer.texture_coordinates[3][0] = 0.0f; - vertex_buffer.texture_coordinates[3][1] = 1.0f; + vertex_buffer.texture_coordinates[0].x = 0.0f; + vertex_buffer.texture_coordinates[0].y = 0.0f; + vertex_buffer.texture_coordinates[1].x = 1.0f; + vertex_buffer.texture_coordinates[1].y = 0.0f; + vertex_buffer.texture_coordinates[2].x = 1.0f; + vertex_buffer.texture_coordinates[2].y = 1.0f; + vertex_buffer.texture_coordinates[3].x = 0.0f; + vertex_buffer.texture_coordinates[3].y = 1.0f; - vertex_buffer.vertexes[0][0] = vertex_left; - vertex_buffer.vertexes[0][1] = vertex_top; - vertex_buffer.vertexes[1][0] = vertex_right; - vertex_buffer.vertexes[1][1] = vertex_top; - vertex_buffer.vertexes[2][0] = vertex_right; - vertex_buffer.vertexes[2][1] = vertex_bottom; - vertex_buffer.vertexes[3][0] = vertex_left; - vertex_buffer.vertexes[3][1] = vertex_bottom; + vertex_buffer.vertexes[0].x = vertex_left; + vertex_buffer.vertexes[0].y = vertex_top; + vertex_buffer.vertexes[1].x = vertex_right; + vertex_buffer.vertexes[1].y = vertex_top; + vertex_buffer.vertexes[2].x = vertex_right; + vertex_buffer.vertexes[2].y = vertex_bottom; + vertex_buffer.vertexes[3].x = vertex_left; + vertex_buffer.vertexes[3].y = vertex_bottom; glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); From 6d8c5c1d75d6a5ffa85003a56e114b2847b83380 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 1 Aug 2019 13:29:28 +0000 Subject: [PATCH 072/128] Updated local copy of Freetype to 2.10.1 --- external/freetype/CMakeLists.txt | 44 +- external/freetype/ChangeLog | 2913 ++++------------- external/freetype/ChangeLog.29 | 2352 +++++++++++++ external/freetype/Jamfile | 2 +- external/freetype/README | 8 +- external/freetype/builds/toplevel.mk | 4 +- external/freetype/builds/unix/aclocal.m4 | 5 +- external/freetype/builds/unix/config.guess | 245 +- external/freetype/builds/unix/config.sub | 13 +- external/freetype/builds/unix/configure | 21 +- external/freetype/builds/unix/configure.ac | 4 +- external/freetype/builds/unix/configure.raw | 2 +- external/freetype/builds/unix/ltmain.sh | 0 external/freetype/builds/vms/LIBS.OPT_IA64 | Bin 0 -> 82 bytes external/freetype/builds/vms/_LINK.OPT_IA64 | Bin 0 -> 14464 bytes external/freetype/builds/vms/ftconfig.h | 2 - external/freetype/builds/vms/vmslib.dat | 28 + .../builds/wince/vc2005-ce/freetype.vcproj | 76 +- .../builds/wince/vc2005-ce/index.html | 10 +- .../builds/wince/vc2008-ce/freetype.vcproj | 76 +- .../builds/wince/vc2008-ce/index.html | 10 +- .../freetype/builds/windows/vc2010/index.html | 2 +- .../builds/windows/visualc/freetype.vcproj | 3 - .../builds/windows/visualc/index.html | 2 +- .../builds/windows/visualce/freetype.dsp | 20 +- .../builds/windows/visualce/freetype.vcproj | 84 +- .../builds/windows/visualce/index.html | 10 +- external/freetype/docs/CHANGES | 56 +- external/freetype/docs/VERSIONS.TXT | 1 + external/freetype/docs/freetype-config.1 | 2 +- .../freetype/docs/reference/site/404.html | 12 +- .../docs/reference/site/ft2-auto_hinter.html | 12 +- .../reference/site/ft2-base_interface.html | 19 +- .../docs/reference/site/ft2-basic_types.html | 12 +- .../docs/reference/site/ft2-bdf_fonts.html | 12 +- .../reference/site/ft2-bitmap_handling.html | 12 +- .../docs/reference/site/ft2-bzip2.html | 12 +- .../reference/site/ft2-cache_subsystem.html | 12 +- .../docs/reference/site/ft2-cff_driver.html | 12 +- .../docs/reference/site/ft2-cid_fonts.html | 12 +- .../reference/site/ft2-color_management.html | 12 +- .../docs/reference/site/ft2-computations.html | 12 +- .../reference/site/ft2-error_code_values.html | 12 +- .../site/ft2-error_enumerations.html | 15 +- .../docs/reference/site/ft2-font_formats.html | 12 +- .../docs/reference/site/ft2-gasp_table.html | 12 +- .../reference/site/ft2-glyph_management.html | 14 +- .../reference/site/ft2-glyph_stroker.html | 12 +- .../reference/site/ft2-glyph_variants.html | 12 +- .../reference/site/ft2-gx_validation.html | 12 +- .../docs/reference/site/ft2-gzip.html | 12 +- .../site/ft2-header_file_macros.html | 12 +- .../reference/site/ft2-header_inclusion.html | 12 +- .../docs/reference/site/ft2-incremental.html | 12 +- .../docs/reference/site/ft2-index.html | 18 +- .../reference/site/ft2-layer_management.html | 12 +- .../reference/site/ft2-lcd_rendering.html | 12 +- .../reference/site/ft2-list_processing.html | 12 +- .../freetype/docs/reference/site/ft2-lzw.html | 12 +- .../docs/reference/site/ft2-mac_specific.html | 12 +- .../reference/site/ft2-module_management.html | 14 +- .../reference/site/ft2-multiple_masters.html | 12 +- .../reference/site/ft2-ot_validation.html | 12 +- .../site/ft2-outline_processing.html | 16 +- .../reference/site/ft2-parameter_tags.html | 12 +- .../docs/reference/site/ft2-pcf_driver.html | 12 +- .../docs/reference/site/ft2-pfr_fonts.html | 12 +- .../docs/reference/site/ft2-properties.html | 12 +- .../reference/site/ft2-quick_advance.html | 12 +- .../docs/reference/site/ft2-raster.html | 21 +- .../docs/reference/site/ft2-sfnt_names.html | 12 +- .../reference/site/ft2-sizes_management.html | 12 +- .../reference/site/ft2-system_interface.html | 12 +- .../reference/site/ft2-t1_cid_driver.html | 12 +- .../reference/site/ft2-truetype_engine.html | 12 +- .../reference/site/ft2-truetype_tables.html | 12 +- .../docs/reference/site/ft2-tt_driver.html | 12 +- .../docs/reference/site/ft2-type1_tables.html | 12 +- .../reference/site/ft2-user_allocation.html | 12 +- .../docs/reference/site/ft2-version.html | 14 +- .../docs/reference/site/ft2-winfnt_fonts.html | 14 +- .../freetype/docs/reference/site/index.html | 18 +- .../reference/site/search/search_index.json | 2 +- .../freetype/docs/reference/site/sitemap.xml | 102 +- .../docs/reference/site/sitemap.xml.gz | Bin 222 -> 221 bytes external/freetype/docs/release | 12 +- external/freetype/include/freetype/freetype.h | 15 +- external/freetype/include/freetype/fterrors.h | 4 + external/freetype/include/freetype/ftglyph.h | 2 +- external/freetype/include/freetype/ftimage.h | 16 +- external/freetype/include/freetype/ftmodapi.h | 2 +- external/freetype/include/freetype/ftoutln.h | 8 +- external/freetype/include/freetype/ftwinfnt.h | 2 +- .../include/freetype/internal/ftcalc.h | 2 +- .../include/freetype/internal/ftobjs.h | 6 +- .../include/freetype/internal/ftstream.h | 11 + .../include/freetype/internal/fttrace.h | 1 + .../include/freetype/internal/internal.h | 1 + .../include/freetype/internal/psaux.h | 8 +- .../freetype/internal/services/svgldict.h | 4 +- .../freetype/include/freetype/internal/sfnt.h | 1 + .../include/freetype/internal/t1types.h | 4 +- .../include/freetype/internal/tttypes.h | 83 +- .../include/freetype/internal/wofftypes.h | 112 + external/freetype/src/autofit/afblue.c | 7 + external/freetype/src/autofit/afblue.dat | 1082 ++++++ external/freetype/src/autofit/afblue.h | 139 +- external/freetype/src/autofit/afcjk.c | 5 +- external/freetype/src/autofit/afglobal.c | 11 + external/freetype/src/autofit/aflatin.c | 58 +- external/freetype/src/autofit/afranges.c | 15 + external/freetype/src/autofit/afscript.h | 6 + external/freetype/src/autofit/afstyles.h | 7 + external/freetype/src/base/ftbbox.c | 12 +- external/freetype/src/base/ftbitmap.c | 15 +- external/freetype/src/base/fterrors.c | 1 + external/freetype/src/base/ftinit.c | 3 + external/freetype/src/base/ftlcdfil.c | 12 +- external/freetype/src/base/ftobjs.c | 4 +- external/freetype/src/base/ftoutln.c | 13 +- external/freetype/src/base/ftstroke.c | 56 +- external/freetype/src/base/ftver.rc | 4 +- external/freetype/src/bdf/bdf.h | 6 +- external/freetype/src/bdf/bdfdrivr.c | 30 +- external/freetype/src/bdf/bdflib.c | 219 +- external/freetype/src/cache/rules.mk | 2 +- external/freetype/src/cff/cffdrivr.c | 4 +- external/freetype/src/cff/cffobjs.c | 2 +- external/freetype/src/cff/cffparse.c | 155 +- external/freetype/src/cff/cffparse.h | 13 + external/freetype/src/gzip/ftgzip.c | 2 +- external/freetype/src/gzip/infblock.c | 5 + external/freetype/src/gzip/infcodes.c | 4 + external/freetype/src/gzip/inflate.c | 10 + external/freetype/src/pcf/pcf.h | 3 +- external/freetype/src/pcf/pcfdrivr.c | 12 +- external/freetype/src/pcf/pcfread.c | 180 +- external/freetype/src/pfr/pfrobjs.c | 2 +- external/freetype/src/psaux/afmparse.c | 3 +- external/freetype/src/psaux/psfixed.h | 3 +- external/freetype/src/psaux/psfont.c | 6 +- external/freetype/src/psaux/psobjs.c | 8 +- external/freetype/src/psaux/psobjs.h | 8 +- external/freetype/src/raster/ftraster.c | 72 +- external/freetype/src/sfnt/rules.mk | 1 + external/freetype/src/sfnt/sfdriver.c | 18 +- external/freetype/src/sfnt/sfnt.c | 1 + external/freetype/src/sfnt/sfobjs.c | 399 +-- external/freetype/src/sfnt/sfobjs.h | 2 +- external/freetype/src/sfnt/sfwoff.c | 434 +++ external/freetype/src/sfnt/sfwoff.h | 41 + external/freetype/src/sfnt/ttcmap.c | 5 +- external/freetype/src/sfnt/ttmtx.c | 6 +- external/freetype/src/smooth/ftgrays.c | 301 +- external/freetype/src/smooth/ftsmooth.c | 2 +- external/freetype/src/tools/apinames.c | 479 +-- external/freetype/src/truetype/ttgload.c | 123 +- external/freetype/src/truetype/ttgxvar.c | 94 +- external/freetype/src/truetype/ttgxvar.h | 1 + external/freetype/src/truetype/ttinterp.c | 383 ++- external/freetype/src/truetype/ttobjs.c | 45 +- external/freetype/src/truetype/ttpload.c | 6 +- external/freetype/src/type1/t1driver.c | 4 +- external/freetype/src/type1/t1load.c | 31 +- external/freetype/src/type42/t42drivr.c | 4 +- external/freetype/src/type42/t42objs.c | 21 +- external/freetype/src/type42/t42parse.c | 13 +- external/freetype/vms_make.com | 236 +- 168 files changed, 7218 insertions(+), 4691 deletions(-) create mode 100644 external/freetype/ChangeLog.29 mode change 100644 => 100755 external/freetype/builds/unix/ltmain.sh create mode 100644 external/freetype/builds/vms/LIBS.OPT_IA64 create mode 100644 external/freetype/builds/vms/_LINK.OPT_IA64 create mode 100644 external/freetype/builds/vms/vmslib.dat create mode 100644 external/freetype/include/freetype/internal/wofftypes.h create mode 100644 external/freetype/src/autofit/afblue.dat create mode 100644 external/freetype/src/sfnt/sfwoff.c create mode 100644 external/freetype/src/sfnt/sfwoff.h diff --git a/external/freetype/CMakeLists.txt b/external/freetype/CMakeLists.txt index 28dc3b3f..e3ffb83b 100644 --- a/external/freetype/CMakeLists.txt +++ b/external/freetype/CMakeLists.txt @@ -135,7 +135,7 @@ project(freetype C) set(VERSION_MAJOR "2") set(VERSION_MINOR "10") -set(VERSION_PATCH "0") +set(VERSION_PATCH "1") # SOVERSION scheme: CURRENT.AGE.REVISION # If there was an incompatible interface change: @@ -234,12 +234,20 @@ if (UNIX) endif () string(REPLACE "/undef " "#undef " FTCONFIG_H "${FTCONFIG_H}") -else() +else () file(READ "${PROJECT_SOURCE_DIR}/include/freetype/config/ftconfig.h" FTCONFIG_H) endif () -file(WRITE "${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h" - "${FTCONFIG_H}") + +set(FTCONFIG_H_NAME "${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h") +if (EXISTS "${FTCONFIG_H_NAME}") + file(READ "${FTCONFIG_H_NAME}" ORIGINAL_FTCONFIG_H) +else () + set(ORIGINAL_FTCONFIG_H "") +endif () +if (NOT (ORIGINAL_FTCONFIG_H STREQUAL FTCONFIG_H)) + file(WRITE "${FTCONFIG_H_NAME}" "${FTCONFIG_H}") +endif () # Create the options file @@ -265,8 +273,16 @@ if (HARFBUZZ_FOUND) "/\\* +(#define +FT_CONFIG_OPTION_USE_HARFBUZZ) +\\*/" "\\1" FTOPTION_H "${FTOPTION_H}") endif () -file(WRITE "${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h" - "${FTOPTION_H}") + +set(FTOPTION_H_NAME "${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h") +if (EXISTS "${FTOPTION_H_NAME}") + file(READ "${FTOPTION_H_NAME}" ORIGINAL_FTOPTION_H) +else () + set(ORIGINAL_FTOPTION_H "") +endif () +if (NOT (ORIGINAL_FTOPTION_H STREQUAL FTOPTION_H)) + file(WRITE "${FTOPTION_H_NAME}" "${FTOPTION_H}") +endif () file(GLOB PUBLIC_HEADERS "include/ft2build.h" "include/freetype/*.h") @@ -333,7 +349,7 @@ endif () if (NOT DISABLE_FORCE_DEBUG_POSTFIX) set(CMAKE_DEBUG_POSTFIX d) -endif() +endif () add_library(freetype @@ -456,7 +472,15 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) string(REPLACE "%LIBS_PRIVATE%" "" # All libs support pkg-config FREETYPE2_PC_IN ${FREETYPE2_PC_IN}) - file(WRITE ${PROJECT_BINARY_DIR}/freetype2.pc ${FREETYPE2_PC_IN}) + set(FREETYPE2_PC_IN_NAME "${PROJECT_BINARY_DIR}/freetype2.pc") + if (EXISTS "${FREETYPE2_PC_IN_NAME}") + file(READ "${FREETYPE2_PC_IN_NAME}" ORIGINAL_FREETYPE2_PC_IN) + else () + set(ORIGINAL_FREETYPE2_PC_IN "") + endif () + if (NOT (ORIGINAL_FREETYPE2_PC_IN STREQUAL FREETYPE2_PC_IN)) + file(WRITE "${FREETYPE2_PC_IN_NAME}" ${FREETYPE2_PC_IN}) + endif () install( FILES ${PROJECT_BINARY_DIR}/freetype2.pc @@ -493,9 +517,9 @@ set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSIO if (WIN32) set(CPACK_GENERATOR ZIP) -else() +else () set(CPACK_GENERATOR TGZ) -endif() +endif () set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries") set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C/C++ Headers") diff --git a/external/freetype/ChangeLog b/external/freetype/ChangeLog index 670e8480..6450a60b 100644 --- a/external/freetype/ChangeLog +++ b/external/freetype/ChangeLog @@ -1,3 +1,579 @@ +2019-07-01 Werner Lemberg + + * Version 2.10.1 released. + ========================== + + + Tag sources with `VER-2-10-1'. + + * docs/VERSION.TXT: Add entry for version 2.10.1. + + * README, Jamfile (RefDoc), src/base/ftver.rc, + builds/windows/vc2010/freetype.vcxproj, + builds/windows/vc2010/index.html, + builds/windows/visualc/freetype.dsp, + builds/windows/visualc/freetype.vcproj, + builds/windows/visualc/index.html, + builds/windows/visualce/freetype.dsp, + builds/windows/visualce/freetype.vcproj, + builds/windows/visualce/index.html, + builds/wince/vc2005-ce/freetype.vcproj, + builds/wince/vc2005-ce/index.html, + builds/wince/vc2008-ce/freetype.vcproj, + builds/wince/vc2008-ce/index.html: s/2.10.0/2.10.1/, s/2100/2101/. + + * include/freetype/freetype.h (FREETYPE_PATCH): Set to 1. + + * builds/unix/configure.raw (version_info): Set to 23:1:17. + * CMakeLists.txt (VERSION_PATCH): Set to 1. + + * include/freetype/fterrors.h (FT_Error_String): Fix C++ compilation. + +2019-06-26 Alexei Podtelezhnikov + + * src/bdf/bdfdrivr.c (bdf_cmap_char_{index,next}): Fix inequality. + + Reported by Armin Hasitzka. + +2019-06-16 Werner Lemberg + + * src/tools/apinames.c: Formatting, minor edits. + +2019-06-16 Werner Lemberg + + [autofit] Disable hinting if no blue zones are available (#56450). + + * src/autofit/afglobal.c (af_face_global_get_metrics): Start again + (with dummy hinter module) if no blue zones are present. + + * src/autofit/aflatin.c (af_latin_metrics_init_blues): Change + signature to return error code. + If no blue zones are found, update `glyph_styles' array to hold + AF_STYLE_NONE_DFLT instead of the current style. + (af_latin_metrics_init): Return internal error code if no blue zones + are found. + +2019-06-16 Werner Lemberg + + Towards better VMS support. + + More to come. + + * builds/vms/LIBS.OPT_IA64, builds/vms/_LINK.OPT_IA64, + builds/vms/vmslib.dat: New files provided by Jouk Jansen + . + + * builds/vms/ftconfig.h: Update, also from Jouk. + +2019-06-13 Werner Lemberg + + * src/autofit/aflatin.c (af_latin_metrics_init_widths): Minor. + +2019-06-13 Alexei Podtelezhnikov + + [smooth] Restore the span buffering for direct mode only. + + The buffer size FT_MAX_GRAY_SPANS is set to 10 spans, which should be + enough to cover the entire scanline for simple glyphs in most cases: + each slightly slanted edge needs up to two spans, plus a filling span + in-between. This is not new, we used to do it before cb4388783cecc. + + * src/smooth/ftgrays.c (gray_TWorker): Add `spans' and `num_spans'. + (gray_hline, gray_sweep): Implement the span buffering. + (gray_raster_render): Use negative `num_spans' to avoid the direct + mode. + +2019-06-12 Alexei Podtelezhnikov + + * include/freetype/ftmodapi.h (FT_DebugHook_Func): Return error. + + Fix a warning by adding a return value as in `TT_RunIns', + which should not be a compatibility issue. + +2019-06-11 Alexei Podtelezhnikov + + * src/truetype/ttobjs.c (tt_check_trickyness_family): Add `const'. + +2019-06-11 Moazin Khatti + + [gzip] Add support for `gzip' encoded header. + + * src/gzip/ftgzip.c (FT_Gzip_Uncompress): Modify the the call to + `inflateInit2' to enable support for `gzip' encoded headers. + +2019-06-10 Alexei Podtelezhnikov + + [type1,type42] Use `const' for string literals. + + * include/freetype/internal/psaux.h (PS_Table_FuncsRec): Updated. + * include/freetype/internal/t1types.h (T1_EncodingRec): Updated. + * src/psaux/psobjs.[ch] (ps_table_add): Updated. + * src/type1/t1load.c (T1_Open_Face, parse_encoding): Updated. + * src/type42/t42objs.c (T42_Open_Face): Updated. + * src/type42/t42parse.c (t42_parse_encoding): Updated. + + * src/cff/cffobjs.c (cff_face_init): Minor. + +2019-06-10 Alexei Podtelezhnikov + + [bdf,pcf] Use `const' for string literals. + + * src/bdf/bdf.h (bdf_property_t): Updated `name'. + * src/bdf/bdflib.c (_bdf_list_split,bdf_create_property, + _bdf_add_property,_bdf_ato*): Updated. + * src/bdf/bdfdrivr.c (bdf_interpret_style): Updated. + * src/pcf/pcfread.c (pcf_intrpret_style): Ditto. + +2019-06-07 Philip Race + + * src/base/ftinit.c (FT_Set_Default_Properties): Fix crash. + + Terminate loop at end of environment. + +2019-05-31 Alexei Podtelezhnikov + + Solidify VC2005 builds. + + * include/freetype/internal/ftcalc.h (FT_MSB) [_MSC_VER]: Explicitly + declare `_BitScanReverse' intrinsic. + * builds/windows/visualc/freetype.vcproj [Debug]: Disable intrinsics. + +2019-05-30 Nikhil Ramakrishnan + + [sfnt] Separate WOFF sources and headers. + + Move WOFF sources and headers to separate files. + + * include/freetype/internal/wofftypes.h, src/sfnt/sfwoff.c, + src/sfnt/sfwoff.h: New files. + + * include/freetype/internal/fttrace.h: Register `sfwoff.c'. + + * include/freetype/internal/internal.h: Define + FT_INTERNAL_WOFF_TYPES_H. + + * include/freetype/internal/sfnt.h: Include FT_INTERNAL_WOFF_TYPES_H. + + * include/freetype/internal/tttypes.h: Move out WOFF structures. + + * src/sfnt/rules.mk: Add `sfwoff.c'. + + * src/sfnt/sfnt.c: Include `sfwoff.c'. + + * src/sfnt/sfobjs.c: Include `sfwoff.h', move out WOFF sources. + +2019-05-30 Werner Lemberg + + [base] Fix `make multi'. + + Reported by Nikhil. + + * src/base/fterrors.c: Include FT_INTERNAL_DEBUG_H. + +2019-05-29 Ben Wagner + + [truetype] Fix copy-and-paste error (#56409). + + * src/truetype/ttgload.c (load_truetype_glyph): Use correct indices + into `unrounded' array for phantom points. + +2019-05-29 Werner Lemberg + + [truetype] Fix 32bit builds (#56404). + + Patch suggested by Ben Wagner . + + * src/truetype/ttgxvar.c (FT_fixedToInt, FT_fixedToFdot6): Remove + harmful cast to unsigned type. + +2019-05-26 Ben Wagner + + * src/truetype/ttgload.c (TT_Process_Simple_Glyph): Improve accuracy. + +2019-05-23 Werner Lemberg + + [truetype] Draw glyphs without deltas in variation font (#56374). + + * src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Always fill + `unrounded' array. + +2019-05-21 Werner Lemberg + + * src/truetype/ttinterp.c (opcode_name): Improve mnemonics. + +2019-05-16 Werner Lemberg + + [truetype] Actually scale varied CVT values. + + Up to now, only the unscaled CVT values were varied; in other words, + the `CVAR' data was never used for bytecode hinting. + + * src/truetype/ttgxvar.c (tt_cvt_ready_iterator): New auxiliary + function. + (tt_face_vary_cvt): Use it to trigger rescaling of CVT values. + +2019-05-16 Werner Lemberg + + [truetype] Use 26.6 format for storing unscaled CVT values. + + If `CVAR' data is applied to variation fonts, fractional values are + possible. + + * include/freetype/internal/tttypes.h (TT_FaceRec): Change type of + `cvt' from `FT_Short' to `FT_Int32'. + + * src/truetype/ttgxvar.c (FT_fdot6ToFixed): New macro. + (tt_face_vary_cvt): Use it to update code to 26.6 format. + + * src/truetype/ttobjs.c (tt_size_run_prep): Update code to 26.6 + format. + + * src/truetype/ttpload.c (tt_face_load_cvt): Stora data in 26.6 + format. + +2019-05-16 Werner Lemberg + + * src/truetype/ttgload.c (load_truetype_glyph): Init `unrounded'. + + This fixes linear advance width values for spacing glyphs. Bug + introduced 2019-05-09. + +2019-05-16 Werner Lemberg + + [truetype] Avoid code duplication. + + * src/truetype/ttobjs.c (tt_size_run_prep): Scale CVT values in this + function. + (tt_size_ready_bytecode): Updated. + * src/truetype/ttgload.c (tt_loader_init): Updated. + +2019-05-13 Jouk Jansen + + * vms_make.com: Updated. Handle `bzip2' directory, too. + +2019-05-13 Werner Lemberg + + * src/psaux/psfont.c (cf2_font_setup): Fix compiler warning. + +2019-05-12 Werner Lemberg + + [truetype] Doh. Fix last commit to make it work. + + Very embarassing :-) + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14701 + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14705 + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14710 + + * src/truetype/ttgload.c (IS_DEFAULT_INSTANCE): Move up and add + argument; update all callers. + (TT_Process_Simple_Glyph): Use it. The `unrounded' array is active + for variation fonts only, thus also enclose related code with + `#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT ... #endif' where + necessary. + Revert commit a113e5d from 2019-05-09, and don't use `extra_points2' + but allocate a temporary array. + Speed up the scaling of the `unrounded' array. + + * src/truetype/ttgxvar.c (FT_fixedToInt, FT_FixedToFdot6): Fix type + conversions and rounding. The unsigned type must have more or equal + bits to the signed type. + +2019-05-09 Werner Lemberg + + [truetype] Increase precision of font variation (#54371). + + This patch makes FreeType use font units in 26.6 format internally + instead of integers. + + * src/truetype/ttgxvar.c (FT_fixedToFdot6): New macro. + (TT_Vary_Apply_Glyph_Deltas): Add argument to output unrounded font + coordinates. + * src/truetype/ttgxvar.h: Updated. + + * src/truetype/ttgload.c (TT_Process_Simple_Glyph): Use + `extra_points2' array to temporarily hold unrounded point + coordinates; use them to compute scaled coordinates and linear + advance width and height. + (load_truetype_code): Adjust similarly. + +2019-05-09 Werner Lemberg + + * src/truetype/ttgload.c (TT_Process_Simple_Glyph): Minor. + +2019-05-08 Alexei Podtelezhnikov + + [smooth] Faster fractions. + + * src/smooth/ftgrays.c (SUBPIXELS): Replace with... + (FRACT): A fractional coordinate macro to use in... + (gray_render_line, gray_render_scanline): ... here. + +2019-05-07 Alexei Podtelezhnikov + + * src/raster/ftraster.c (Draw_Sweep): Unbreak. + +2019-05-05 Alexei Podtelezhnikov + + * src/raster/ftraster.c: Clean-ups. + +2019-05-05 Werner Lemberg + + * src/truetype/ttgxvar.c: More use of `FT_fdot14ToFixed'. + +2019-05-04 Alexei Podtelezhnikov + + * src/smooth/ftgrays.c (gray_render_line): Small shortcut. + +2019-05-04 Werner Lemberg + + Various clang 8.0 static analyzer fixes. + + Reported by Sender Ghost . + + * src/autofit/afcjk.c (af_cjk_hints_compute_edges): Catch a corner + case where `edge->first' could be NULL. + + * src/pfr/pfrobjs.c (pfr_slot_load): Remove unnecessary test of + `size'. + + * src/raster/ftraster.c (Draw_Sweep): Catch a corner case where + `draw_right' might be NULL. + + * src/sfnt/ttmtx.c (tt_face_get_metrics): Fix limit test for + `aadvance'. + Ensure `abearing' always hold a meaningful result. + + * src/truetype/ttgload.c (load_truetype_glyph): Ensure `subglyph' is + not NULL before accessing it. + * src/truetype/ttgxvar.c (TT_Set_Named_Instance): Remove unnecessary + test of `namedstyle'. + + * src/type42/t42parse.c (t42_parser_done): Ensure + `parser->root.funcs.done' is not NULL before accessing it. + +2019-05-03 Alexei Podtelezhnikov + + Miscellaneous macro updates. + + * src/base/ftoutln.c (SCALED): Updated. + * src/smooth/ftgrays.c (SCALED): Ditto. + (FLOOR, ROUND, CEILING): Removed. + * src/psaux/psfixed.h (cf2_fracToFixed): Updated. + +2019-05-02 Alexei Podtelezhnikov + + Tweak LCD filtering. + + * src/base/ftlcdfil.c (ft_lcd_filter_fir, _ft_lcd_filter_legacy): + Choose direction from bitmap's pixel_mode. + * include/freetype/internal/ftobjs.c (FT_Bitmap_LcdFilterFunc): + Updated. + * src/smooth/ftsmooth.c (ft_smooth_render_generic): Updated. + +2019-05-02 Werner Lemberg + + * vms_make.com: Updated (#56253). + + Remove no longer existing directories (`autohint', `otlayout'). + Update used base extensions. + Activate `autofit' module. + Add `gxvalid' module. + Update copyright notices. + +2019-04-29 Alexei Podtelezhnikov + + [smooth] Simplify cubic Bézier flattening. + + The previous implementation is correct but it is too complex. + The revised algorithm is based on the fact that each split moves + the control points closer to the trisection points on the chord. + The corresponding distances are good surrogates for the curve + deviation from the straight line. + + This cubic flattening algorithm is somewhat similar to the conic + algorithm based the distance from the control point to the middle of + the chord. The cubic distances, however, decrease less predictably + but are easy enough to calculate on each step. + + The new algorithm produces slightly larger number of splits, which is + compensated by its simplicity. The overall rendering performance is + improved by 1-2%. The larger number of splits does not necessarily + result in higher quality, which stays comparable. + + * src/smooth/ftgrays.c (gray_render_cubic): Replace the split + condition. + +2019-04-26 Alexei Podtelezhnikov + + [smooth] Bithacks and cosmetics. + + * src/smooth/ftgrays.c (gray_record_cell, gray_set_cell, gray_hline, + gray_render_conic, gray_convert_glyph_inner): Updated. + +2019-04-25 Alexei Podtelezhnikov + + Optimize Bézier bisections. + + This change makes bisections faster by 20-30%. When inlined into + `gray_render_cubic', this makes the function faster by 10% and is + noticeable in the overall rendering performance. + + * src/raster/ftraster.c (Split_Conic, Split_Cubic): Use shifts and + refactor. + * src/smooth/ftgrays.c (gray_split_conic, gray_split_cubic): Ditto. + * src/base/ftstroke.c (ft_conic_split, ft_cubic_split): Ditto. + * src/base/ftbbox.c (cubic_peak): Use shifts. + +2019-04-23 Werner Lemberg + + * src/sfnt/ttcmap.c (tt_cmap12_next): Remove dead code. + + Found by clang 8.0's static analyzer and reported by Sender Ghost + . + +2019-04-23 Werner Lemberg + + [base] Fix thinko in previous commit. + + * src/base/ftbitmap.c (FT_Bitmap_Blend): Check final width, not + target pitch. + + Problem reported by Sender Ghost . + +2019-04-22 Werner Lemberg + + * src/base/ftbitmap.c (FT_Bitmap_Blend): Check target pitch. + + Problem reported by Sender Ghost . + +2019-04-22 Werner Lemberg + + Fix return value of `FT_Set_Named_Instance' (#56186). + + * src/truetype/ttgxvar.c (TT_Set_Named_Instance): Correctly handle + internal return value -1 of `TT_Set_Var_Design'. + +2019-04-18 Werner Lemberg + + [pcf] Fix handling of undefined glyph (#56067). + + This commit fixes the changes from 2018-07-21, which broke charmap + iteration. We now add the default character as a new glyph with + index 0, thus increasing the number of glyphs by one (as before). + + * src/pcf/pcfread.c (pcf_get_metrics): Adjust to new artificial + glyph with index 0. + Limit number of elements to 65534. + (pcf_get_bitmaps): Ditto. + Unify two loops into one; this avoids allocation of an intermediate + array. + (pcf_get_encodings): Don't flip indices but copy glyph metrics of + default character to index 0. + Also handle invalid default character. + + * docs/CHANGES: Updated. + +2019-04-15 Minmin Gong + + * CMakeLists.txt: Avoid rewriting of unchanged configuration files. + + Reported as + + https://savannah.nongnu.org/patch/index.php?9755 + +2019-04-15 JDG + + * src/tools/apinames.c (main): Fix error message. + + Reported as + + https://savannah.nongnu.org/patch/?9796 + +2019-04-11 Alexei Podtelezhnikov + + [smooth] Fix segfault in direct mode (#56092). + + * src/base/ftoutln.c (FT_Outline_Render): Set missing clip_box for + direct mode. + * src/smooth/ftgrays.c (gray_raster_render): Use it. + +2019-04-06 Werner Lemberg + + * src/sfnt/ttcmap.c (tt_get_glyph_name): Pacify compiler (#56061). + + This is for Visual Studio 2019 on ARM. + +2019-04-06 Werner Lemberg + + For distribution, replace `.tar.bz2' with `.tar.xz' bundles. + + * builds/toplevel.mk (build): Do it. + + * README, docs/CHANGES, docs/release: Updated. + +2019-04-06 Antony Lee + + Make `glyph_name' parameter to `FT_Get_Name_Index' a `const'. + + * include/freetype/freetype.h (FT_Get_Name_Index), + include/freetype/internal/ftobjs.h (FT_Face_GetGlyphNameIndexFunc), + include/freetype/internal/services/svgldict.h + (FT_GlyphDict_NameIndexFunc), src/base/ftobjs.c (FT_Get_Name_Index), + src/cff/cffdrivr.c (cff_get_name_index), src/sfnt/sfdriver.c + (sfnt_get_name_index), src/type1/t1driver.c (t1_get_name_index), + src/type42/t42drivr.c (t42_get_name_index): Add `const' to second + argument. + +2019-03-31 Armin Hasitzka + + [cff] Fix boundary checks. + + 642bc7590c701c8cd35a9f60fa899cfa518b17ff introduced dynamically + allocated memory when parsing CFF files with the "old" engine. Bounds + checks have never been updated, however, leading to pointless + comparisons of pointers in some cases. This commit presents a + solution for bounds checks in the CFF module with an extended logic + for the "old" engine while staying as concise as possible for the + "new" one. + + * src/cff/cffparse.h: Introduce the struct `CFF_T2_StringRec' and + the additional field `t2_strings' within `CFF_ParserRec'. + + * src/cff/cffparse.c (cff_parser_within_limits): Move all boundary + checks into this new function and update the rest of `cffparse.c' to + use it. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12137 + +2019-03-20 Werner Lemberg + + [autofit] Fix Mongolian blue zone characters. + + * src/autofit/afblue.dat: Use U+200D (ZERO-WIDTH JOINER) characters + to get medial forms for some Mongolian characters. + * src/autofit/afblue.c, src/autofit/afblue.h: Regenerated. + +2019-03-19 Werner Lemberg + + [autofit] Add support for Mongolian script. + + As a de-facto standard, layouts using this script are constructed + horizontally line by line, then the lines are rotated clockwise for + vertical display. + + * src/autofit/afblue.dat: Add blue zone data for Mongolian. + * src/autofit/afblue.c, src/autofit/afblue.h: Regenerated. + + * src/autofit/afscript.h: Add Mongolian standard characters. + + * src/autofit/afranges.c, src/autofit/afstyles.h: Add Mongolian + data. + 2019-03-15 Werner Lemberg * Version 2.10.0 released. @@ -2525,2345 +3101,10 @@ src/smooth/ftspic.h, src/truetype/ttpic.c, src/truetype/ttpic.h: Removed. -2018-05-01 Werner Lemberg - - * Version 2.9.1 released. - ========================= - - - Tag sources with `VER-2-9-1'. - - * docs/VERSION.TXT: Add entry for version 2.9.1. - * docs/CHANGES: Updated. - - * README, Jamfile (RefDoc), builds/windows/vc2005/freetype.vcproj, - src/base/ftver.rc, builds/windows/vc2005/index.html, - builds/windows/vc2008/freetype.vcproj, - builds/windows/vc2008/index.html, - builds/windows/vc2010/freetype.vcxproj, - builds/windows/vc2010/index.html, - builds/windows/visualc/freetype.dsp, - builds/windows/visualc/freetype.vcproj, - builds/windows/visualc/index.html, - builds/windows/visualce/freetype.dsp, - builds/windows/visualce/freetype.vcproj, - builds/windows/visualce/index.html, - builds/wince/vc2005-ce/freetype.vcproj, - builds/wince/vc2005-ce/index.html, - builds/wince/vc2008-ce/freetype.vcproj, - builds/wince/vc2008-ce/index.html: s/2.9/2.9.1/, s/29/291/. - - * include/freetype/freetype.h (FREETYPE_PATCH): Set to 1. - - * builds/unix/configure.raw (version_info): Set to 22:1:16. - * CMakeLists.txt (VERSION_PATCH): Set to 1. - - * include/freetype/ftgasp.h: Use FT_BEGIN_HEADER and FT_END_HEADER. - -2018-04-26 Werner Lemberg - - Another fix for handling invalid format 2 cmaps. - - Sigh. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8003 - - * src/sfnt/ttcmap.c (tt_cmap2_char_next): Adjust condition to avoid - an endless loop. - -2018-04-24 Ben Wagner - - [base] Avoid undefined behaviour in lcd filtering code (#53727). - - * src/base/ftlcdfil.c (ft_lcd_filter_fir, _ft_lcd_filter_legacy): - Ensure `height > 0'. - -2018-04-22 Werner Lemberg - - * src/base/ftoutln.c (FT_Outline_Decompose): Improve error tracing. - -2018-04-22 Alexei Podtelezhnikov - - [base] Fix bitmap emboldening. - - Bug introduced after release 2.8. - - * src/base/ftbitmap.c (ft_bitmap_assure_buffer): We use - `FT_QALLOC_MULT', which doesn't zero out the buffer. Adjust the - bitmap copying code to take care of this fact. - -2018-04-22 Werner Lemberg - - Another fix for handling invalid format 2 cmaps. - - The previous commit was incomplete. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7928 - - * src/sfnt/ttcmap.c (tt_cmap2_char_next): Adjust condition to avoid - an endless loop. - -2018-04-19 Werner Lemberg - - Fix handling of invalid format 2 cmaps. - - The problem was introduced after the last release. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7828 - - * src/sfnt/ttcmap.c (tt_cmap2_char_next): Avoid endless loop. - -2018-04-17 Werner Lemberg - - [truetype] Integer overflow issues. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7739 - - * src/truetype/ttinterp.c (Ins_CEILING): Use FT_PIX_CEIL_LONG. - -2018-04-16 Werner Lemberg - - [truetype] Integer overflow issues. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7718 - - * src/truetype/ttinterp.c (Ins_MIRP): Use ADD_LONG. - -2018-04-15 Alexei Podtelezhnikov - - [build] Use `info' function of make 3.81. - - * configure, docs/INSTALL, docs/INSTALL.CROSS, docs/INSTALL.GNU, - docs/INSTALL.UNIX, docs/MAKEPP: Bump make version requirements. - - * builds/detect.mk (std_setup): Replace `echo' with `info'. - (dos_setup): Removed. - * builds/unix/install.mk, builds/modules.mk, builds/dos/detect.mk, - builds/windows/detect.mk, builds/os2/detect.mk: Updated. - * builds/newline: No longer needed. - -2018-04-15 Werner Lemberg - - [truetype]: Limit `SLOOP' bytecode argument to 16 bits. - - This fixes - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7707 - - * src/truetype/ttinterp.c (Ins_SLOOP): Do it. - -2018-04-14 Werner Lemberg - - [truetype] Integer overflow issues. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7652 - - * src/truetype/ttinterp.c (Ins_MDAP): Use SUB_LONG. - -2018-04-14 Werner Lemberg - - [autofit] Update to Unicode 11.0.0. - - But no support new scripts (volunteers welcomed). - - * src/autofit/afranges.c (af_arab_nonbase_uniranges, - af_beng_nonbase_uniranges, af_cakm_nonbase_uniranges, - af_deva_nonbase_uniranges, af_geor_uniranges, - af_gujr_nonbase_uniranges, af_mlym_nonbase_uniranges, - af_nkoo_nonbase_uniranges, af_telu_nonbase_uniranges, - af_hani_uniranges): Add new data. - -2018-04-10 Nikolaus Waxweiler - - * CMakeLists.txt, builds/cmake/FindHarfBuzz.cmake: Extensive - modernization measures. - - This brings up the minimum required CMake version to 2.8.12. - - The installation paths follow the GNU defaults now, e.g. installing on a - 64 bit host will place binaries into the lib64/ folder on e.g. Fedora. - - Symbols are hidden by default (e.g. `-fvisibility=hidden' on GCC). - - CMake will no longer look for a C++ compiler. - - Library and .so version now match the Autotools build. - - Comments in the build file and informational messages now use platform - agnostic example commands. - - ftoption.h and ftconfig.h are written directly without a redundant `-new' - copy. - - External dependencies are expressed as option()s and will turn up as such - in cmake-gui. - - Internal: Properties such as dependencies and include directories are now - privately set on the freetype library instead of globally. - - The CPack definitions have been cleaned up, the `make dist' has been - removed. Source packages generated with CPack don't contain Autotools - files and aren't used by the maintainers anyway. - - On Windows, src/base/ftver.rc is compiled to decorate the library with - version and copyright information. - - A pkg-config file is now generated and installed. - -2018-04-09 Werner Lemberg - - [truetype] Integer overflow issues. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7453 - - * src/truetype/ttinterp.c (Round_Super, Round_Super_45): Use - ADD_LONG and SUB_LONG. - -2018-04-06 Alexei Podtelezhnikov - - [windows, wince] Clean up legacy project files. - - * builds/wince/vc2005-ce/freetype.vcproj, - builds/wince/vc2008-ce/freetype.vcproj, - builds/windows/vc2005/freetype.vcproj, - builds/windows/vc2008/freetype.vcproj, - builds/windows/visualce/freetype.vcproj, - builds/windows/visualce/freetype.dsp, - builds/windows/visualc/freetype.vcproj, - builds/windows/visualc/freetype.dsp: Remove per-file compile flags. - -2018-04-04 Werner Lemberg - - [cff, type1] Sanitize `BlueFuzz' and `BlueShift'. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7371 - - * src/cff/cffload.c (cff_load_private_dict): Sanitize - `priv->blue_shift' and `priv->blue_fuzz' to avoid overflows later - on. - - * src/type1/t1load.c (T1_Open_Face): Ditto. - -2018-04-04 Ben Wagner - - * src/truetype/ttobjs.c (trick_names): Add 3 tricky fonts (#53554), - `DFHei-Md-HK-BF', `DFKaiShu-Md-HK-BF' and `DFMing-Bd-HK-BF'. - (tt_check_trickyness_sfnt_ids): Add checksums for 3 tricky fonts - in above. - -2018-04-01 Werner Lemberg - - * builds/toplevel.mk (work): Use $(SEP). - - This fixes the `make refdoc' using Cygwin: $(CAT) is `type' on this - platform, and this program only understands backslashes in paths. - - Reported by Nikhil Ramakrishnan . - -2018-03-30 Werner Lemberg - - [truetype] Fix memory leak (only if tracing is on). - - * src/truetype/ttgxvar.c (TT_Get_MM_Var) [FT_DEBUG_LEVEL_TRACE}: Fix - it. - -2018-03-23 Ben Wagner - - [sfnt] Correctly handle missing bitmaps in sbix format (#53404). - - * src/sfnt/ttfsbit.c (tt_face_load_sbix_image): Fix return value. - -2018-03-23 Ben Wagner - - [truetype] Fix advance of empty glyphs in bitmap fonts (#53393). - - * src/truetype/ttgload.c (TT_Load_Glyph): Apply scaling to metrics - for empty bitmaps. - -2018-03-22 Werner Lemberg - - Remove `ftlcdfil.c' and `ftfntfmt.c' from build files (#53415). - - builds/amiga/makefile, builds/amiga/makefile.os4, - builds/amiga/smakefile, builds/mac/FreeType.m68k_cfm.make.txt, - builds/mac/FreeType.m68k_far.make.txt, - builds/mac/FreeType.ppc_carbon.make.txt, - builds/mac/FreeType.ppc_classic.make.txt, - builds/symbian/freetype.mmp, builds/wince/vc2005-ce/freetype.vcproj, - builds/wince/vc2008-ce/freetype.vcproj, - builds/windows/vc2005/freetype.vcproj, - builds/windows/vc2008/freetype.vcproj, - builds/windows/vc2010/freetype.vcxproj, - builds/windows/vc2010/freetype.vcxproj.filters, - builds/windows/visualc/freetype.dsp, - builds/windows/visualc/freetype.vcproj, - builds/windows/visualce/freetype.dsp, - builds/windows/visualce/freetype.vcproj, vms_make.com: Do it. - -2018-03-13 Werner Lemberg - - * src/sfnt/ttcmap.c (tt_cmap2_validate): Fix potential numeric - overflow. - -2018-03-13 Werner Lemberg - - Fix cmap format 2 handling (#53320). - - The patch introduced for #52646 was not correct. - - * src/sfnt/ttcmap.c (tt_cmap2_char_next): Adjust condition. - -2018-03-10 Nikolaus Waxweiler - - * CMakeLists.txt (BASE_SRCS): Update to changes from 2018-03-05. - -2018-03-09 Chun-wei Fan - - * CMakeLists.txt [win32]: Allow MSVC DLL builds (#53287). - - Do not limit DLL builds to MinGW, since we already have - `__declspec(dllexport)' directives in `ftconfig.h'. - Also suppress more warnings for POSIX functions. - -2018-03-08 Hugh McMaster - - Make installation of `freetype-config' optional (#53093). - - * builds/unix/configure.raw: Add option `--enable-freetype-config' - and set `INSTALL_FT2_CONFIG'. - * builds/unix/unix-def.in (INSTALL_FT2_CONFIG): Define. - * builds/unix/install.mk (install): Handle it. - -2018-03-05 Werner Lemberg - - Make `ftlcdfil.c' part of the `base' module. - - `ftobjs.c' needs `ft_lcd_padding'. - - Problem reported by duhuanpeng <548708880@qq.com>. - - * modules.cfg (BASE_EXTENSIONS): Don't include `ftlcdfil.c'. - - * src/base/ftbase.c: Include `ftlcdfil.c'. - * src/base/rules.mk (BASE_SRC): Add `ftlcdfil.c'. - * src/base/Jamfile (_sources): Adjusted. - - * docs/INSTALL.ANY: Updated. - -2018-03-05 Werner Lemberg - - Make `ftfntfmt.c' part of the `base' module. - - `ftobjs.c' needs `FT_Get_Font_Format'. - - Problem reported by duhuanpeng <548708880@qq.com>. - - * modules.cfg (BASE_EXTENSIONS): Don't include `ftfntfmt.c'. - - * src/base/ftbase.c: Include `ftfntfmt.c'. - * src/base/rules.mk (BASE_SRC): Add `ftfntfmt.c'. - * src/base/Jamfile (_sources): Adjusted. - - * docs/INSTALL.ANY: Updated. - -2018-03-01 Werner Lemberg - - * src/truetype/ttinterp.c (TT_RunIns): Fix tracing arguments. - -2018-02-23 Werner Lemberg - - * builds/unix/configure.raw: Need HarfBuzz 1.3.0 or newer. - - Problem reported by Alan Coopersmith . - -2018-02-17 Werner Lemberg - - [sfnt] Prefer `CBDT'/`CBLC' over `glyf' table (#53154). - -2018-02-06 Werner Lemberg - - [truetype] Integer overflow issues. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=6027 - - * src/truetype/ttinterp.c (Ins_MSIRP, Ins_MIAP, Ins_MIRP): Use - SUB_LONG; avoid FT_ABS. - -2018-02-04 Alexei Podtelezhnikov - - [unix] Use -fvisibility=hidden. - - It is now widely recommended that ELF shared libraries hide symbols - except those with explicit __attribute__((visibility("default"))). - This is supported by all major compilers and should rather be an - option in libtool. - - * builds/unix/configure.raw: Add -fvisibility=hidden to CFLAGS. - * builds/unix/ftconfig.in, builds/vms/ftconfig.h, - include/freetype/config/ftconfig.h (FT_EXPORT): Use visibility - attribute. - -2018-01-27 Werner Lemberg - - [truetype] Better protection against invalid VF data. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=5739 - - Bug introduced in commit 08cd62deedefe217f2ea50e392923ce8b5bc7ac7. - - * src/truetype/ttgxvar.c (TT_Set_Var_Design): Always initialize - `normalizedcoords'. - -2018-01-27 Werner Lemberg - - * src/truetype/ttinterp.c (Ins_GETVARIATION): Avoid NULL reference. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=5736 - -2018-01-27 Werner Lemberg - - * src/truetype/ttgxvar.c (tt_set_mm_blend): Minor. - -2018-01-27 Werner Lemberg - - [truetype] Better trace VF instances. - - * src/truetype/ttgxvar.c (ft_var_to_normalized): Don't emit number - of coordinates. - (TT_Get_MM_Var): Trace instance indices names. - (TT_Set_Var_Design): Updated. - -2018-01-27 Werner Lemberg - - [truetype] Beautify tracing of VF axis records. - - * src/truetype/ttgxvar.c (TT_Get_MM_Var): Show axis records in a - table-like manner. - -2018-01-26 Ben Wagner - - [truetype] Fix multiple calls of `FT_Get_MM_Var' (#52955). - - * src/truetype/ttgxvar.c (TT_Get_MM_Var): Set - `face->blend->num_axis' in case we have to initialize the - `face->blend'. - -2018-01-23 Alexei Podtelezhnikov - - [apinames] Anonymous version map for GNU linker. - - * src/tools/apinames.c (PROGRAM_VERSION): Set to 0.3. - (OutputFormat): Add `OUTPUT_GNU_VERMAP'. - (names_dump): Handle it. - (usage): Updated. - (main): Handle new command line flag `-wL'. - -2018-01-21 Alexei Podtelezhnikov - - [unix] Call libtool to clean up. - - * builds/unix/install.mk (clean_project_unix, distclean_project_unix): - Use libtool. - * builds/freetype.mk: Minor. - -2018-01-18 Alexei Podtelezhnikov - - * src/base/ftver.rc: Fix mingw-w64 compilation. - -2018-01-18 Alexei Podtelezhnikov - - [build] Enable VERSIONINFO resource for Cygwin/MinGW. - - * builds/unix/configure.raw: Check for resource compiler. - * builds/unix/unix-cc.in: Conditionally set up resource compiler. - * builds/freetype.mk: Add conditional rule for `ftver.rc'. - * src/base/ftver.rc: Copyright notice and year update. - -2018-01-18 Alexei Podtelezhnikov - - [build] Move VERSIONINFO resource. - - * builds/windows/vc2010/freetype.vcxproj: Updated. - * builds/windows/ftver.rc: Move file from here... - * src/base/ftver.rc: ... to here. - -2018-01-12 Alexei Podtelezhnikov - - [build] Expand dllexport/dllimport to Cygwin/MinGW. - - * include/freetype/config/ftconfig.h: Respect DLL_EXPORT, - s/_MSC_VER/_WIN32/. - * builds/unix/ftconfig.in: Replicate here. - * builds/vms/ftconfig.h: Replicate here. - -2018-01-12 Alexei Podtelezhnikov - - [build] Improve and document MSVC build. - - * include/freetype/config/ftconfig.h: Guard dllexport/dllimport - attributes with _DLL and FT2_DLLIMPORT. - * builds/windows/vc2010/index.html: Update documentation. - -2018-01-10 Steve Robinson - - * CMakeLists.txt [win32]: Suppress warnings for POSIX functions. - -2018-01-10 Ewald Hew - - [psaux] Correctly handle Flex features (#52846). - - * src/psaux/psintrp.c (cf2_interpT2CharString) : Do not move if doing Flex. - -2018-01-09 Alexei Podtelezhnikov - - * builds/windows/vc2010/freetype.sln: Synchronize with the project. - -2018-01-08 Werner Lemberg - - * Version 2.9 released. - ======================= - - - Tag sources with `VER-2-9'. - - * docs/VERSION.TXT: Add entry for version 2.9. - - * README, Jamfile (RefDoc), builds/windows/vc2005/freetype.vcproj, - builds/windows/vc2005/index.html, - builds/windows/vc2008/freetype.vcproj, - builds/windows/vc2008/index.html, - builds/windows/vc2010/freetype.vcxproj, - builds/windows/vc2010/index.html, - builds/windows/visualc/freetype.dsp, - builds/windows/visualc/freetype.vcproj, - builds/windows/visualc/index.html, - builds/windows/visualce/freetype.dsp, - builds/windows/visualce/freetype.vcproj, - builds/windows/visualce/index.html, - builds/windows/ftver.rc, - builds/wince/vc2005-ce/freetype.vcproj, - builds/wince/vc2005-ce/index.html, - builds/wince/vc2008-ce/freetype.vcproj, - builds/wince/vc2008-ce/index.html: s/2.8.1/2.9/, s/281/29/. - - * include/freetype/freetype.h (FREETYPE_MINOR): Set to 9. - (FREETYPE_PATCH): Set to 0. - - * builds/unix/configure.raw (version_info): Set to 22:0:16. - * CMakeLists.txt (VERSION_PATCH): Set to 0. - -2018-01-07 Werner Lemberg - - Add check for librt, needed for `ftbench' (#52824). - - * builds/unix/configure.raw (LIB_CLOCK_GETTIME): Define; this will - hold `-lrt' if necessary. - - * builds/unix/unix-cc.in (LIB_CLOCK_GETTIME): New variable. - -2018-01-07 Ewald Hew - - [psaux] Fix Type 1 glyphs with too many stem hints. - - According to the CFF specification, charstrings can have up to 96 stem - hints. Due to hint replacement routines in Type 1 charstrings, some - glyphs are rejected by the Adobe engine, which implements the above - limit. This fix turns off hinting for such glyphs. - - * src/psaux/pshints.c (cf2_hintmap_build): Reset the error from calling - `cf2_hintmask_setAll' on a problematic Type 1 charstring and turn off - hinting. - -2018-01-06 Werner Lemberg - - Add `FT_Done_MM_Var'. - - This is necessary in case the application's memory routines differ - from FreeType. A typical example is a Python application on Windows - that calls FreeType compiled as a DLL via the `ctypes' interface. - - * include/freetype/ftmm.h, src/base/ftmm.c (FT_Done_MM_Var): Declare - and define. - - * docs/CHANGES: Updated. - -2018-01-03 Werner Lemberg - - [truetype] Round offsets of glyph components only if hinting is on. - - * src/truetype/ttgload.c (TT_Process_Composite_Component): Implement - it. - -2018-01-03 Werner Lemberg - - * src/truetype/ttgxvar.c (ft_var_to_design): Remove dead code. - - This is a better fix than the previous commit, which is now - reverted. - -2018-01-03 Alexei Podtelezhnikov - - Move internal LCD-related declarations. - - * include/freetype/ftlcdfil.h (ft_lcd_padding, ft_lcd_filter_fir): - Move from here... - * include/freetype/internal/ftobjs.h: ... to here. - -2018-01-03 Alexei Podtelezhnikov - - * include/freetype/config/ftconfig.h (FT_EXPORT, FT_EXPORT_DEF) - [_MSC_VER]: Limit Visual C++ attributes. - -2018-01-03 Werner Lemberg - - [truetype] Make blend/design coordinate round-tripping work. - - Behdad reported that setting blend coordinates, then getting design - coordinates did incorrectly return the default instance's - coordinates. - - * src/truetype/ttgxvar.c (tt_set_mm_blend): Fix it. - -2017-12-31 Werner Lemberg - - * src/sfnt/ttcmap.c (tt_cmap2_char_next): Fix endless loop. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4838 - -2017-12-31 Werner Lemberg - - Synchronize other Windows project files. - - * builds/windows/*: Add missing files. - -2017-12-31 Werner Lemberg - - Update Visual C 2010 project files. - - Problem reported by Hin-Tak. - - * builds/windows/vc2010/freetype.vcxproj: Add files `ftbdf.c' and - `ftcid.c'. - Sort entries. - * builds/windows/vc2010/freetype.vcxproj.filter: Ditto. - Fix members of `FT_MODULE' group. - -2017-12-30 Werner Lemberg - - * builds/vms/ftconfig.h: Synchronize with unix `ftconfig.in' file. - -2017-12-28 Werner Lemberg - - * builds/unix/ftconfig.in: Synchronize with main `ftconfig.h' file. - - Reported by Nikolaus. - -2017-12-27 Werner Lemberg - - Fix compiler warnings. - - * src/base/ftbitmap.c (ft_bitmap_assure_buffer): Make `pitch' and - `new_pitch' unsigned. - - * src/base/ftpsprop.c: Include FT_INTERNAL_POSTSCRIPT_PROPS_H. - -2017-12-27 Werner Lemberg - - Fixes for `make multi'. - - * include/freetype/internal/ftpsprop.h: Use `FT_BASE_CALLBACK'. - (ps_property_get): Harmonize declaration with corresponding - function typedef. - - * include/freety[e/internal/fttrace.h: Add `trace_psprops'. - - * src/base/ftpsprop.c: Include necessary header files. - (FT_COMPONENT): Define. - (ps_property_set): Tag with `FT_BASE_CALLBACK_DEF'. - (ps_property_get): Tag with `FT_BASE_CALLBACK_DEF'. - Harmonize declaration with corresponding function typedef. - -2017-12-27 Werner Lemberg - - Provide support for intra-module callback functions. - - This is needed especially for `make multi' with C++. - - * include/freetype/config/ftconfig.h (FT_BASE_CALLBACK, - FT_BASE_CALLBACK_DEF): New macros. - -2017-12-25 Ewald Hew - - Move PostScript drivers' property handlers to `base'. - - This reduces the amount of duplicated code across PostScript - drivers. - - * src/cff/cffdrivr.c, src/cid/cidriver.c, src/type1/t1driver.c - ({cff,cid,t1}_property_{get,set}): Moved to... - * include/freetype/internal/ftpsprop.h: ...this new file. - (ps_property_{get,set}): New functions to replace moved ones. - - * src/base/ftpsprop.c: New file that implements above functions. - - * include/freetype/internal/internal.h - (FT_INTERNAL_POSTSCRIPT_PROPS_H): New macro. - - * src/cff/cffdrivr.c, src/cid/cidriver.c, src/type1/t1driver.c: - Updated. - - * src/base/Jamfile, src/base/rules.mk (BASE_SRC), src/base/ftbase.c: - Updated. - -2017-12-20 Werner Lemberg - - Speed up FT_Set_Var_{Design,Blend}_Coordinates if curr == new. - - We exit early if the current design or blend coordinates are - identical to the new ones. - - * src/truetype/ttgxvar.c (tt_set_mm_blend, TT_Set_Var_Design): - Implement it, returning internal error code -1 if there will be no - variation change. - - * src/type1/t1load.c (t1_set_mm_blend): Ditto. - - * src/base/ftmm.c (FT_Set_Var_Design_Coordinates, - FT_Set_MM_Blend_Coordinates, FT_Set_Var_Blend_Coordinates): Updated. - -2017-12-18 Werner Lemberg - - [sfnt] Fix charmap type 2 iterator (#52646). - - The subsetted demo font of the report that exhibits the bug has a - very unusual type 2 cmap for Unicode(!): It contains only two - sub-headers, one for one-byte characters (covering the range 0x20 to - 0xFA), and a second one for higher byte 0x01 (just for character - code U+0131). - - Before this commit, the iterator wasn't able to correctly handle a - sub-header for higher byte 0x01. - - * src/sfnt/ttcmap.c (tt_cmap2_char_next): Fix character increment - for outer loop. - -2017-12-18 Matthias Clasen - - [truetype] Fix clamping, minor tracing code beautification. - - * src/truetype/ttgxvar.c (ft_var_to_normalized): Trace number of - design coordinates. - Use clamped value. - -2017-12-18 Werner Lemberg - - * src/*/*: Only use `ft_' and `FT_' variants of stdc library stuff. - -2017-12-18 Werner Lemberg - - * src/truetype/ttgxvar.c (tt_face_vary_cvt): Add size guard (#52688). - -2017-12-18 Werner Lemberg - - [truetype] Fix previous commit. - - * src/truetype/ttgload.c (TT_Process_Simple_Glyph): Correctly handle - unhinted phantom points, which must be properly scaled. - -2017-12-18 Werner Lemberg - - [truetype] Don't apply HVAR and VVAR deltas twice (#52683). - - * src/truetype/ttgload.c (TT_Process_Simple_Glyph): Always adjust - `pp1' to `pp4', except if we have an HVAR and/or VVAR table. - - * src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Handle - alternative code branch identically w.r.t. presence of an HVAR - and/or VVAR table. - -2017-12-17 Jonathan Kew - - [truetype] Correctly handle variation font phantom points (#52683). - - * src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Fix phantom - point indices. - -2017-12-17 Jonathan Kew - - Fix incorrect advance width scaling (#52683). - - * src/base/ftadvance.c (FT_Get_Advances): Always respect the - FT_LOAD_NO_SCALE flag if present. - -2017-12-16 Alexei Podtelezhnikov - - * builds/windows/vc2010/freetype.vcxproj: AfterBuild copy. - * objs/.gitignore: Ignore almost everything. - -2017-12-11 Werner Lemberg - - Fix compiler warning (#52640). - - * src/base/ftbitmap.c (ft_bitmap_assure_buffer): Remove unused - variable. - -2017-12-08 Azzuro - - * builds/windows/vc2010/freetype.vcxproj: Adjust output directory. - - This allows builds with different configurations in parallel. - -2017-12-08 Werner Lemberg - - Fix `make setup dos', second try (#52622). - - * builds/detect.mk (dos_setup): Don't use literal `>' character at - all. Mixing the different escaping rules from make, dos, and - windows is too fragile. - -2017-12-08 Werner Lemberg - - [docmaker] Fix code section parsing. - - Stuff like - - { - - } - - confused the parser, which incorrectly treated `' as a markup - tag. - - * src/tools/docmaker/content.py (ContentProcessor::process_content): - Apply `re_markup_tags' only outside of code sections. - -2017-12-08 Werner Lemberg - - New `ftdriver.h' file, covering all driver modules. - - This reduces redundancy and increases synergy; it also reduces the - number of header files. - - * include/freetype/config/ftheader.h (FT_DRIVER_H): New macro. - (FT_AUTOHINTER_H, FT_CFF_DRIVER_H, FT_TRUETYPE_DRIVER_H, - FT_PCF_DRIVER_H, FT_TYPE1_DRIVER_H): Make them aliases to - FT_DRIVER_H. - - * include/freetype/ftautoh.h, include/freetype/ftcffdrv.h, - include/freetype/ftpcfdrv.h, include/freetype/ftt1drv.h, - include/freetype/ftttdrv.h: Replaced with... - * include/freetype/ftdriver.h: ...this new file. - (FT_CFF_HINTING_ADOBE, FT_T1_HINTING_ADOBE): Renamed to... - (FT_HINTING_ADOBE): ... this new macro. - (FT_CFF_HINTING_FREETYPE, FT_T1_HINTING_FREETYPE): Renamed to... - (FT_HINTING_FREETYPE): ... this new macro. - - * src/*/*: Updated accordingly. - -2017-12-08 Werner Lemberg - - Move `ftdriver.h' to `ftdrv.h'. - - * include/freetype/internal/ftdriver.h: Renamed to... - * include/freetype/internal/ftdrv.h: ... this name. - - * include/freetype/internal/internal.h (FT_INTERNAL_DRIVER_H): - Updated. - -2017-12-08 Werner Lemberg - - Fix access to uninitalized memory (#52613). - - Also reported as - - https://bugs.chromium.org/p/chromium/issues/detail?id=791317 - - * src/base/ftbitmap.c (ft_bitmap_assure_buffer): If increasing the - bitmap size needs a larger bitmap buffer, assure that the new memory - areas are initialized also. - -2017-12-08 Werner Lemberg - - Fix `make setup dos' (#52622). - - * builds/detect.mk (dos_setup): Properly escape literal `>' - character. - -2017-12-07 Werner Lemberg - - Fix C++ compilation. - - * src/psaux/psauxmod.h: Use FT_CALLBACK_TABLE macro where necessary. - - * src/smooth/ftsmooth.c (ft_smooth_render_generic): Fix warning. - -2017-12-07 Werner Lemberg - - Fix `make multi'. - - * include/freetype/internal/fttrace.h: Remove unused tracing macros. - s/pshalgo2/pshalgo/. - Add `trace_cffdecode'. - * src/pshinter/pshalgo.c (FT_COMPONENT): Updated. - - * src/cff/cffload.c: Include FT_INTERNAL_POSTSCRIPT_AUX_H. - * src/cff/cffobjs.c: Include FT_SERVICE_METRICS_VARIATIONS_H and - FT_SERVICE_CFF_TABLE_LOAD_H. - - * src/cid/cidriver.c: Include FT_INTERNAL_POSTSCRIPT_AUX_H. - - * src/psaux/cffdecode.c: Include FT_FREETYPE_H and - FT_INTERNAL_DEBUG_H. - (FT_COMPONENT): Define. - * src/psaux/cffdecode.h: Include FT_INTERNAL_POSTSCRIPT_AUX_H. - * src/psaux/psauxmod.h: Include FT_INTERNAL_POSTSCRIPT_AUX_H. - Declare `cff_builder_funcs' and `ps_builder_funcs'. - * src/psaux/psft.c: Include `psobjs.h' and `cffdecode.h'. - * src/psaux/psobjs.c : Include `psauxmod.h'. - -2017-12-07 Werner Lemberg - - * include/freetype/config/ftheader.h: Some clean-up. - - This commit removes documentation of deprecated macros and does some - minor streamlining. - -2017-12-06 Werner Lemberg - - * builds/symbian/bld.inf: Updated. - -2017-12-06 Werner Lemberg - - New header file `ftparams.h' that collects all parameter tags. - - * include/freetype/config/ftheader.h (FT_PARAMETER_TAGS_H): New - macro. - (FT_TRUETYPE_UNPATENTED_H, FT_UNPATENTED_HINTING_H): Define it to - `ftparams.h'. - - * include/freetype/ftautoh.h, include/freetype/ftcffdrv.h, - include/freetype/ftincrem.h, include/freetype/ftlcdfil.h, - include/freetype/ftsnames.h, include/freetype/ftt1drv.h: Include - FT_PARAMETER_TAGS_H. - Move FT_PARAM_TAG_XXX definitions to... - * include/freetype/ftparams.h: ...this new file. - - * include/freetype/ttunpat.h: Remove. No longer needed. - -2017-12-05 Werner Lemberg - - Improve tracing messages by using singular and plural forms. - - * src/*/*.c: Implement it. - -2017-12-04 Werner Lemberg - - [truetype] Allow shared points in `cvar' table (#52532). - - * src/truetype/ttgxvar.c (tt_face_vary_cvt): Implement it by copying - and adjusting the corresponding code from - `TT_Vary_Apply_Glyph_Deltas'. - -2017-11-28 Werner Lemberg - - [truetype] Improving tracing of composite glyphs. - - * src/truetype/ttgload.c (TT_Load_Composite_Glyph) - [FT_DEBUG_LEVEL_TRACE]: Show composite glyph information. - -2017-11-27 Werner Lemberg - - [type1] Allow (again) `/Encoding' with >256 elements (#52464). - - In version 2.6.1, this has been disallowed to better reject - malformed fonts; however, this restriction was too strong. This - time, we only take the first 256 elements into account, since - encoding arrays are always accessed with a 8bit integer, according - to the PostScript Language Reference. - - * src/type1/t1load.c (parse_encoding): Implement it. - -2017-11-27 Jan Alexander Steffens (heftig) - - Fix last commit (#52522). - - * builds/freetype.mk: Set `FT_OPTION_H' and `FTOPTION_FLAG' - properly if we have `ftoption.h' in `BUILD_DIR'. - -2017-11-24 Werner Lemberg - - [unix] Install a massaged `ftoption.h' file (#51780). - - * builds/unix/configure.raw (ftoption_set, ftoption_unset): New - auxiliary functions to construct... - (FTOPTION_H_SED): ... this new variable. - Apply it as a sed argument while copying `ftoption.h' to the - `builds/unix' directory (using `AC_CONFIG_FILES'). - Simplify code of test that checks cpp's computation of bit length - (the test previously created an empty `ftoption.h' file and deleted - it immediately afterwards); without this change, it can happen on my - GNU/Linux box that `configure's execution of `config.status' doesn't - create `ftoption.h' (no idea why this happens). - - * builds/unix/install.mk (install): Install - `builds/unix/ftoption.h'. - - * builds/unix/unix-def.in (DISTCLEAN): Updated. - - * builds/unix/.gitignore: Updated. - -2017-11-23 Tor Andersson - - Silence unused function warnings (#52465). - - Some static function declarations cause unused function warnings if - certain config options are turned off via `ftoption.h'. - - * src/base/ftbase.h, src/base/ftrfork.c, src/sfnt/ttbdf.h, - src/truetype/ttgxvar.h: Add #ifdef guards around these sections. - -2017-11-22 Ewald Hew - - * src/psaux/psft.c (cf2_setGlyphWidth): Check format before setting. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4377 - -2017-11-22 Ewald Hew - - [psaux] Fix CFF advance widths. (#52466) - - Glyph advance widths were being written to the new `PS_Decoder' but not - saved to the underlying format specific decoder. This caused pure CFF - fonts to have bad advance width. - - * include/freetype/internal/psaux.h (PS_Decoder): Change `glyph_width' - field to pointer. - Remove unused fields. - * src/psaux/psobjs.c (ps_decoder_init): Change `glyph_width' from copy - to reference. - Remove unused. - * src/psaux/psft.c (cf2_setGlyphWidth): Update code. - -2017-11-15 Vlad Tsyrklevich - - * include/freetype/ftrender.h: Fix `FT_Renderer_RenderFunc' type. - -2017-11-14 Nikolaus Waxweiler - - Use Adobe hinting engine for `light' hinting of both CFF and Type 1. - - Since Ewald Hew factored the Adobe hinting engine out of the CFF - driver code, we can now use it on Type 1 (and CID) font formats, as - both have the same hinting philosophy. - - This change activates the Adobe hinter when in LIGHT mode, and - therefore always unless explicitly asking for the auto-hinter. This - makes LIGHT behavior consistent with CFF fonts. As of this commit, - the hinting engine table looks as follows. - - LIGHT NORMAL - ------------------------- - TrueType Auto v40 - CFF Adobe Adobe - Type 1 Adobe Adobe - -2017-11-10 Yuri Levchenko - - * CMakeLists.txt: Add `DISABLE_FORCE_DEBUG_PREFIX' option. - -2017-11-06 Alexei Podtelezhnikov - - * src/base/ftobjs.c (FT_Load_Glyph): Relocate condition. - -2017-11-06 Alexei Podtelezhnikov - - * src/smooth/ftgrays.c (gray_set_cell): Fix uninitialized variables. - -2017-11-03 Ewald Hew - - [psaux] Fix PostScript interpreter rewinding in Type 1 mode. (#52251) - - The interpreter in Type 1 mode rewinds the charstring after collecting - all hints for building the initial hintmap (commit d52dd7f). However, - some charstrings use `endchar' in a final subroutine call, rewinding to - the start of that subroutine, and only a small section of the actual - glyph is drawn. - - * src/psaux/psintrp.c (cf2_interpT2CharString) : - Ensure we are on the top level charstring before rewinding. - -2017-11-03 suzuki toshiya - - [truetype] Add more tricky fonts. - - See the report by Yang Yinsen. - https://lists.gnu.org/archive/html/freetype-devel/2017-11/msg00000.html - - * src/truetype/ttobjs.c (trick_names): Add `DFGothic-EB', - `DFGyoSho-Lt', `DFHSGothic-W5', `DFHSMincho-W3' and `DFHSMincho-W7'. - (tt_check_trickyness_sfnt_ids): Add checksums for DFGothic-EB, - DFGyoSho-Lt, DFHSGothic-W5, DFHSMincho-W3 and DFHSMincho-W7. Also - add checksums for DLCLiShu and DLCHayBold which their family names - were already listed but their checksums were previously unknown. - -2017-11-01 Alexei Podtelezhnikov - - [smooth] Fix complex rendering at high ppem. - - We used to split large glyphs into horizontal bands and continue - bisecting them still horizontally if that was not enough. This is - guaranteed to fail when a single scanline cannot fit into the - rendering memory pool. Now we bisect the bands vertically so that - the smallest unit is a column of the band height, which is guranteed - to fit into memory. - - * src/smooth/ftgrays.c (gray_convert_glyph): Implement it. - -2017-10-20 Alexei Podtelezhnikov - - [smooth] Improve complex rendering at high ppem. - - At large sizes almost but not exactly horizontal segments can quickly - drain the rendering pool. This patch at least avoids filling the pool - with trivial cells. Beyond this, we can only increase the pool size. - - Reported, analyzed, and tested by Colin Fahey. - - * src/smooth/ftgrays.c (gray_set_cell): Do not record trivial cells. - -2017-10-20 Alexei Podtelezhnikov - - [base] Improve tracing in FT_Load_Glyph, FT_*_Size. - - * src/base/ftobjs.c (FT_Load_Glyph): Tag tracing messages with - function name, glyph index, and load flags. - (FT_Select_Metrics, FT_Request_Metrics): Remove all tracing. - (FT_Select_Size, FT_Request_Size): Improve tracing. - -2017-10-18 Alexei Podtelezhnikov - - [base] Improve tracing in FT_Render_Glyph. - - * src/base/ftobjs.c (FT_Render_Glyph_Internal): Add total coverage - calculations and downgrade Netpbm dump to bitmap:7. - -2017-10-15 Ewald Hew - - [cff] Fix segfault on missing `psaux' (#52218) - - * src/cff/cffload.c (cff_done_blend): Add a check for possible nullptr. - - * modules.cfg: Update dependency list. - -2017-10-15 Alexei Podtelezhnikov - - [base, cff] Fix MSVC warnings. - - * src/base/ftobjs.c (FT_New_Library): C4702: unreachable code. - (ft_glyphslot_preset_bitmap): C4244: possible loss of data. - * src/cff/cffload.c (cff_blend_doBlend): C4244: possible loss of data. - Turn `sum' into unsigned. - -2017-10-14 Alexei Podtelezhnikov - - [base] Netpbm image tracing. - - * src/base/ftobjs.c (FT_Load_Glyph): Trace bitmap size. - (FT_Render_Glyph_Internal): Trace bitmap in Netpbm format. - - * src/smooth/ftgrays.c (gray_sweep): Sweep remnants of span tracing. - -2017-10-14 Alexei Podtelezhnikov - - * builds/windows/ftdebug.c (FT_Message): Print to stderr. - * builds/wince/ftdebug.c (FT_Message): Ditto. - -2017-10-14 Behdad Esfahbod - - [afshaper] Delay creating `hb_set' objects until needed. - - In runs on Noto Naskh Arabic, this results in 89 sets created - instead of 340 before. Makes auto-hinter setup with HarfBuzz - enabled 20% to 30% faster. - - * src/autofit/afshaper.c (af_shaper_get_coverage): Implement it. - -2017-10-12 Ewald Hew - - [type1, cid] Add hinting engine switch. - - Implement property service in `type1' and `cid' drivers to allow - switching between FreeType or Adobe hinting engine when both are - available. - - * src/cid/cidriver.c (cid_property_{set,get}, cid_services), - src/type1/t1driver.c (t1_property_{set,get}, t1_services): Add - Properties service. - - * src/cid/cidobjs.c (cid_driver_init), src/type1/t1objs.c - (T1_Driver_Init): Add default property values. - -2017-10-12 Ewald Hew - - Add T1_CONFIG_OPTION_OLD_ENGINE configuration option. - - This controls whether the old Type 1 engine gets compiled into FreeType. - It is disabled by default. - - * devel/ftoption.h, include/freetype/config/ftoption.h - (T1_CONFIG_OPTION_OLD_ENGINE): New macro. - - * include/freetype/internal/psaux.h (PS_Decoder): Remove unused field. - * include/freetype/internal/psaux.h, src/cid/cidgload.c - (cid_load_glyph), src/psaux/psauxmod.c, src/psaux/psobjs.c - (ps_builder_add_point), src/psaux/t1decode.c - (t1_lookup_glyph_by_stdcharcode, t1_decoder_parse_glyph, - t1operator_seac, t1_decoder_parse_charstrings), src/psaux/t1decode.h, - src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Surround - relevant code with macro. - Minor code changes. - -2017-10-12 Ewald Hew - - Extract width parsing from Type 1 parser. - - Duplicate the fast advance width calculations from the old parser. - This is to facilitate adding options for compiling out the old parser. - - * src/psaux/t1decode.{c,h} (t1_decoder_parse_metrics): New function. - * include/freetype/internal/psaux.h (T1_Decoder_Funcs): New entry - `parse_metrics'. - * src/psaux/psauxmod.c: Set the new entry. - - * src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String), - src/cid/cidgload.c (cid_load_glyph): Separate - conditional for selecting engine. - -2017-10-09 Werner Lemberg - - * src/base/ftoutln.c (FT_Outline_Translate): Fix integer overflow. - - Reported as - - https://bugs.chromium.org/p/chromium/issues/detail?id=772775 - -2017-10-08 Werner Lemberg - - * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Integer overflows. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3579 - -2017-10-07 Werner Lemberg - - [sfnt] Adjust behaviour of PS font names for variation fonts. - - * src/sfnt/sfdriver.c (sfnt_get_var_ps_name): Use a named instance's - PS name only if no variation is applied. - -2017-10-07 Werner Lemberg - - [cff, truetype] Adjust behaviour of named instances. - - This commit completely separates the interaction between named - instances and variation functions. In particular, resetting the - variation returns to the current named instance (if set) and not to - the base font. - - As a side effect, variation functions no longer change the named - instance index. - - * src/cff/cffobjs.c (cff_face_init): Use MM service's `set_instance' - function. - Also apply `MVAR' table to named instances. - - * src/truetype/ttgxvar.c (TT_Get_MM_Var): Add cast. - (tt_set_mm_blend): No longer check whether requested variation - coincides with a named instance. - (TT_Set_Var_Design): Use current named instance for default - coordinates. - * src/truetype/ttobjs.c (tt_face_init): Use `TT_Set_Named_Instance'. - -2017-10-07 Werner Lemberg - - Make `FT_Set_Named_Instance' work. - - * src/cff/cffdrivr.c (cff_set_instance): New function. - (cff_service_multi_masters): Register it. - - * src/truetype/ttgxvar.c (TT_Set_Named_Instance): New function. - * src/truetype/ttgxvar.h: Updated. - * src/truetype/ttdriver.c (tt_service_gx_multi_masters): Register - it. - - * src/type1/t1load.c (T1_Reset_MM_Blend): New function. - * src/type1/t1load.h: Updated. - * src/type1/t1driver.c (t1_service_multi_masters): Register it. - -2017-10-07 Werner Lemberg - - Make `FT_FACE_FLAG_VARIATION' work. - - * include/freetype/internal/tttypes.h (TT_Face): Remove - `is_default_instance'; this can be replaced with a combination of - `FT_IS_VARIATION' and `FT_IS_INSTANCE'. - - * src/cff/cffdrivr.c (cff_get_advances): Updated. - - * src/sfnt/sfdriver.c (sfnt_get_ps_name), src/sfnt/sfobjs.c - (sfnt_init_face): Updated. - - * src/truetype/ttdriver.c (tt_get_advances), src/truetype/ttgload.c - (TT_Process_Simple_Glyph, load_truetype_glyph, IS_DEFAULT_INSTANCE), - src/truetype/ttgxvar.c (tt_set_mm_blend): Updated. - * src/truetype/ttgxvar.c (TT_Set_MM_Blend, TT_Set_Var_Design): - Handle `FT_FACE_FLAG_VARIATION'. - - * src/type1/t1load.c (T1_Set_MM_Blend, T1_Set_MM_Design): Handle - `FT_FACE_FLAG_VARIATION'. - -2017-10-07 Werner Lemberg - - New function `FT_Set_Named_Instance'. - - No effect yet. - - * src/base/ftmm.c (FT_Set_Named_Instance): New function. - - * include/freetype/ftmm.h: Updated. - -2017-10-07 Werner Lemberg - - Add macros for checking whether a font variation is active. - - * include/freetype/freetype.h (FT_FACE_FLAG_VARIATION, - FT_IS_VARIATION): New macros. - No effect yet. - -2017-10-07 Werner Lemberg - - Add framework for setting named instance in MM service. - - * include/freetype/internal/services/svmm.h (FT_Set_Instance_Func): - New function typedef. - (MultiMasters): Add `set_instance' member. - (FT_DEFINE_SERVICE_MULTIMASTERSREC): Updated. - - * src/cff/cffdrivr.c (cff_service_multi_masters), - src/truetype/ttdriver (tt_service_gx_multi_masters), - src/type1/t1driver.c (t1_service_multi_masters): Updated. - -2017-10-07 Werner Lemberg - - [type1] Minor code shuffling. - - * src/type1/t1load.c (T1_Set_MM_Blend): Make it a wrapper of... - (t1_set_mm_blend): ...this new function. - (T1_Set_MM_Design): Use `t1_set_mm_blend'. - -2017-10-05 Werner Lemberg - - * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Fix integer - overflow. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3539 - -2017-10-05 Werner Lemberg - - Fix compiler warnings. - - * src/cff/cffdrivr.c (cff_ps_get_font_extra): Avoid code that relies - on numeric overflow. - Add cast. - - * src/smooth/ftsmooth.c (ft_smooth_render_generic): Fix variable - types, add cast. - -2017-10-04 John Tytgat - - [cff] Add support for `FSType'. - - * include/freetype/internal/cfftypes.h (CFF_FontRec): Add - `font_extra' entry. - - * src/cff/cffdrivr.c (cff_ps_get_font_extra): New function to - retrieve FSType info from the embedded PostScript data. - (cff_service_ps_info): Register function. - - * src/cff/cffload.c (cff_font_done): Free `font_extra'. - -2017-09-30 Alexei Podtelezhnikov - - Signedness fixes in bitmap presetting. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3514. - - * src/raster/ftrend1.c (ft_raster1_render): Explicitly signed height. - * src/smooth/ftsmooth.c (ft_smooth_render_generic): Ditto. - * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Explicitly unsigned - subtraction. - -2017-09-29 Alexei Podtelezhnikov - - Bitmap metrics presetting [2/2]. - - * src/base/ftobjs.c (FT_Load_Glyph): Preset the bitmap metrics when - appropriate but `FT_Render_Glyph' is not called. - * include/freetype/freetype.h (FT_GlyphSlotRec): Document the change. - -2017-09-28 Alexei Podtelezhnikov - - [smooth, raster] Miscellaneous cleanups. - - * src/raster/ftrend1.c (ft_raster1_render): Clean up the exit. - * src/smooth/ftsmooth.c (ft_smooth_render_generic): Reduce - translations and clean up the exit. - (ft_smooth_render_lcd, ft_smooth_render_lcd): Remove unused `error'. - -2017-09-28 Ben Wagner - - [truetype] Really, really fix #52082. - - * src/truetype/ttinterp.c (Ins_MDRP): Correct conditional. - -2017-09-28 Werner Lemberg - - * src/psaux/psintrp.c (cf2_doStems): Fix integer overflow. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3510 - -2017-09-28 Ewald Hew - - * src/cid/cidgload.c (cid_slot_load_glyph): Fix memory leak. - - Reported as - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3489 - -2017-09-28 Alexei Podtelezhnikov - - Bitmap metrics presetting [1/2]. - - This mainly just extracts the code for presetting the bitmap metrics - from the monochrome, grayscale, and LCD renderers into a separate - function. - - * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): New function that - calculates prospective bitmap metrics for the given rendering mode. - * include/freetype/internal/ftobjs.h (ft_glyphslot_preset_bitmap): - Declare it. - - * src/base/ftlcdfil.c (ft_lcd_padding): New helper function that adds - padding to CBox taking into account pecularities of LCD rendering. - * include/freetype/ftlcdfil.h (ft_lcd_padding): Declare it. - - * src/raster/ftrend1.c (ft_raster1_render): Reworked to use - `ft_glyphslot_preset_bitmap'. - * src/smooth/ftsmooth.c (ft_smooth_render_generic): Ditto. - (ft_smooth_render_lcd, ft_smooth_render_lcd): The pixel_mode setting - is moved to `ft_glyphslot_preset_bitmap'. - -2017-09-28 Ewald Hew - - [psaux] Fix compiler warning. - - * src/psaux/pshints.c (cf2_hintmap_dump): Add switch for tracing - code. - -2017-09-27 Werner Lemberg - - * src/sfnt/ttload.c (tt_face_load_font_dir): Fix compiler warning. - -2017-09-25 Werner Lemberg - - [psaux] Fix compiler warnings. - - * src/psaux/psft.c (cf2_initLocalRegionBuffer): Remove redundant - test. - - * src/psaux/psintrp.c (cf2_interpT2CharString) - : Add casts. - - * src/psaux/psobjs.c (ps_decoder_init): Add cast. - -2017-09-25 Ewald Hew - - [psaux] Minor fixes. - - * include/freetype/internal/psaux.h, src/psaux/psobjs.{c,h}: - Rearrange `ps_builder_init' arguments to conventional order. - - * src/psaux/psft.c (cf2_decoder_parse_charstrings): Add a check and - notice for `SubFont' in Type 1 mode. - -2017-09-25 Ewald Hew - - [psaux] Move `psdecode' into `psobjs'. - - As the former only contains a single procedure, move it into - `psobjs' for simplicity. Also change the parameter order to the - conventional one. - - * src/psaux/psdecode.c (ps_decoder_init): Moved to... - * src/psaux/psobjs.c: ...Here. - * src/psaux/psdecode.h, src/psaux/psobjs.h: Ditto. - - * include/freetype/internal/psaux.h (PSAux_ServiceRec): Update - `ps_decoder_init' function signature. - - * src/cff/cffgload.c, src/cid/cidgload.c, src/type1/t1gload.c: - Update calls. - - * src/psaux/psaux.c, src/psaux/psauxmod.c: Update includes. - - * src/psaux/Jamfile (_sources), src/psaux/rules.mk (PSAUX_DRV_SRC): - Update file references. - -2017-09-25 Ewald Hew - - [psaux] Fix Type 1 hinting. - - Type 1 hinting breaks sometimes when mid-charstring hints should - have been in the initial hintmap. This fix adds a preprocessing - pass that reads all hints and builds the correct initial hintmap - first, before proceeding to build the glyph outline. - - * src/psaux/psintrp.c (cf2_interpT2CharString): New - `initial_map_ready' boolean flag. - Ignore outline commands and hint changes on first pass. - : Add section to build hintmap and rewind. - -2017-09-25 Ewald Hew - - [psaux] Add tracing for hints. - - * src/psaux/pshints.c (cf2_hintmap_dump): New function. - (cf2_hintmap_insertHint): Trace incoming and inserted hints. - (cf2_hintmap_build): Dump hintmap before and after hint adjustment. - -2017-09-25 Ewald Hew - - [psaux] Minor fixes. - - * src/psaux/psintrp.c (cf2_interpT2CharString): Fix check for pop - results. - s/font->decoder/decoder/ where necessary. - : Use - offset parameter in `cf2_doStems' instead of doing correction for - left-sidebearing. - -2017-09-25 Ewald Hew - - [cid] Use the new engine. - - * src/cid/cidgload.c: Update includes. - (cid_load_glyph, cid_slot_load_glyph): Implement changes to glyph - loading code as with `type1' module. - -2017-09-25 Ewald Hew - - [cid] Add Adobe engine configuration. - - This is similar to what was done in the `type1' module. - - * src/cid/cidriver.c (t1cid_driver_class): Update declaration. - * src/cid/cidobjs.c: Include FT_TYPE1_DRIVER_H. - (cid_driver_init): Update code. - -2017-09-25 Ewald Hew - - [psaux] Change subfont synthesis for CID fonts. - - Change `t1_make_subfont' to take in the Private dict record as an - argument. This is because Type 1 and CID font records in FreeType - have this in different places. - - * src/psaux/psobjs.c (t1_make_subfont): Change `T1_Face' to - `FT_Face' so that CID is also accepted. - Take `PS_Private' as an argument and let caller figure out where the - Private dict actually is. - Update references. - - * include/freetype/internal/psaux.h, src/psaux/psobjs.h: Update - declaration. - - * src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Update - call. - -2017-09-25 Ewald Hew - - [type1] Switch to Adobe engine. - - * src/type1/t1objs.c (T1_Driver_Init): Set default to Adobe engine. - -2017-09-25 Ewald Hew - - [psaux] Extend Adobe interpreter (seac). - - This concludes the changes needed to add Type 1 support. - - * src/psaux/psintrp.c: Update includes. - (cf2_interpT2CharString) : Implement this similarly to - implied seac for CFF. - - * src/psaux/t1decode.c (t1_lookup_glyph_by_stdcharcode_ps): New - function to look up the glyph index. - - * src/psaux/psft.c (cf2_getT1SeacComponent, - cf2_freeT1SeacComponent): New functions to get the charstrings for - seac components. - - * src/psaux/t1decode.h, src/psaux/psft.h: Update declarations. - -2017-09-25 Ewald Hew - - [psaux] Extend Adobe interpreter (flex in callothersubr). - - * src/psaux/psintrp.c (cf2_interpT2CharString) - : Fix Flex feature handling (OtherSubrs 0, 1, - 2). - : Do not actually move the `glyphPath' while doing - flex. This is to avoid closing the current contour. - -2017-09-25 Ewald Hew - - [psaux] Extend Adobe interpreter (callothersubr). - - * src/psaux/psintrp.c (cf2_interpT2CharString) - : Copy code from - `t1_decoder_parse_charstrings' (in `t1decode.c'). - OtherSubr 3 (change hints) should reset the hintmask, so that the - new hints are applied. - Fix function calls and stack access. - -2017-09-25 Ewald Hew - - [psaux] Extend Adobe interpreter (pop). - - * src/psaux/psintrp.c (cf2_interpT2CharString): Change how unhandled - OtherSubr results are stored. Implement the PostScript stack using - an array. - : Ensure that the stack is not cleared after getting - `OtherSubr' results. - Fix stack access. - -2017-09-25 Ewald Hew - - [psaux] Extend Adobe interpreter (callsubr). - - * src/psaux/psintrp.c (cf2_interpT2CharString) : - Type 1 mode. - - * src/psaux/psft.c (cf2_initLocalRegionBuffer): Add Type 1 mode. - -2017-09-25 Ewald Hew - - [psaux] Extend Adobe interpreter (div, four-byte numbers). - - * src/psaux/psintrp.c (cf2_interpT2CharString) : Add - Type 1 mode. Type 1 requires large integers to be followed by - `div'; cf. `Adobe Type 1 Font Format', section 6.2. - : Push Type 1 four-byte numbers as `Int' always. This is - to ensure `div' and `callsubr' get values they can use. - -2017-09-25 Ewald Hew - - [psaux] Extend Adobe interpreter (hints). - - * src/psaux/psintrp.c (cf2_interpT2CharString) : Add correction for left sidebearing in Type 1 mode. - Allow adding hints mid-charstring. - : Translate into equivalent commands - for three normal stem hints. This requires some recalculation of - stem positions. - Correction for left sidebearing. - -2017-09-25 Ewald Hew - - [psaux] Extend Adobe interpreter (hsbw, sbw). - - * src/psaux/psintrp.c (cf2_doStems): `hsbw' or `sbw' must be the - first operation in a Type 1 charstring. - (cf2_interpT2CharString): Remove unused variables. - : `hsbw' or `sbw' - must be the first operation in a Type 1 charstring. - : Fix data access and add correction for - left sidebearing. - -2017-09-25 Ewald Hew - - [psaux] Extend Adobe interpreter (setcurrentpoint). - - * src/psaux/psintrp.c (cf2_interpT2CharString) - : Fix stack access. - -2017-09-25 Ewald Hew - - [psaux] Extend Adobe interpreter (closepath). - - * src/psaux/psintrp.c (cf2_interpT2CharString) : - Use the right builder function. We can use the `haveWidth' boolean - already present, instead of implementing `parse_state'. - -2017-09-25 Ewald Hew - - [psaux] Add Type 1 operations to Adobe CFF interpreter. - - The following Type 1 specific ops have been added (copied from - `t1decode'): - - closepath - vstem3 - hstem3 - seac - sbw - callothersubr - pop - setcurrentpoint - hsbw - - The following require a Type 1 mode, because of differences in - specification: - - hstem - vstem - vmoveto - callsubr - div - rmoveto - hmoveto - Numbers - - The subsequent commits will implement these changes and adapt - accesses of data and objects to the new interpreter. - - NOTE: Will not compile in the meantime! - - * src/psaux/psintrp.c: Add opcodes to enum. - (cf2_interpT2CharString): Copy relevant code over from - `t1_decoder_parse_charstrings' (in `t1decode.c'). - -2017-09-25 Ewald Hew - - [type1] Fixes for rendering. - - The Type 1 advance width calculation passes null for glyph slot, - etc, which can cause null pointer access in the new interpreter. - Fall back to the old one for now. - - Fix the large glyph retry code and ensure hinting and scaling flags - are set properly. - - * src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Add a - check for metrics_only. - Set the `force_scaling' flag. - (T1_Parse_Glyph): Updated. - (T1_Load_Glyph): Add `hinting' and `scaled' flags. - -2017-09-25 Ewald Hew - - [psaux] Add missing objects (2/2). - - Synthesize a `SubFont' object for Type 1 fonts. This is used in the - interpreter to access Private dict data, which are stored in - different places for Type 1 and CFF. This allows the same data to - be used in either mode. - - * src/psaux/psobjs.c (t1_make_subfont): New procedure to copy - required values to a dummy `CFF_SubFont' object. This is similar to - `cff_make_private_dict'. - * src/psaux/psobjs.h: Add the new declaration. - - * include/freetype/internal/psaux.h, src/psaux/psauxmod.c: Ditto. - Add this to the PSAux Service for future use with CID fonts. - - * src/type1/t1gload.c: Include FT_INTERNAL_CFF_TYPES_H. - (T1_Parse_Glyph_And_Get_Char_String): Add the call. - -2017-09-25 Ewald Hew - - [psaux] Add missing objects for Type 1 (1/2). - - Move `CF2_Font' instance to `PS_Decoder'. This is the context for - the interpreter and since it is currently stored in `CFF_Font', is - unavailable in Type 1 mode. - - * include/freetype/internal/psaux.h (T1_Decoder, PS_Decoder): New - `cf2_instance' field. - - * src/psaux/psdecode.c (ps_decoder_init): Copy `cf2_instance' to - `PS_Decoder'. - - * src/psaux/t1decode.c (t1_decoder_done): Add finalization code. - - * src/psaux/psft.c (cf2_decoder_parse_charstrings): Update accesses. - -2017-09-25 Ewald Hew - - Allow `type1' module to use the Adobe engine. - - Add the callback and some conditionals to switch between the two - engines. - - * include/freetype/internal/psaux.h (T1_Decoder_FuncsRec): Change - function declarations. - * src/psaux/psauxmod.c (T1_Decoder_FuncsRec): Register the - callbacks. - - * src/psaux/psobjs.c (ps_builder_add_point): Add conditionals for - number conversion. - - * src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Add code - to choose which renderer to use. - - * src/cid/cidgload.c (cid_load_glyph): Update call. - * src/base/ftobjs.c, src/psaux/psobjs.c, src/type1/t1gload.c: Update - includes. - -2017-09-25 Ewald Hew - - [type1] Add Adobe engine configuration. - - Use the previously changed PS_Driver in type1 module to store - hinting engine configuration. - - * include/freetype/ftt1drv.h: New file. - Duplicate and rename config options from CFF. - * include/freetype/config/ftheader.h (FT_TYPE1_DRIVER_H): New macro. - - * src/type1/t1driver.c (t1_driver_class): Update declaration. - * src/type1/t1objs.c: Include FT_TYPE1_DRIVER_H. - (T1_Driver_Init): Update code. - -2017-09-25 Ewald Hew - - [cff] Move and rename `CFF_Driver'. - - This is so that we can use the same hinting engine parameters for - Type 1. - - * include/freetype/internal/cffotypes.h (CFF_Driver): Rename and - move to... - * include/freetype/internal/psaux.h (PS_Driver): ...here. - - * src/cff/cffdrivr.c, src/cff/cffgload.c, src/cff/cffload.c, - src/cff/cffobjs.c, src/cff/cffobjs.h, src/psaux/psft.c, - src/psaux/psobjs.c: Update references. - -2017-09-25 Ewald Hew - - [psaux, type1] Reorganize object fields. - - Make some fields more generic, so that we can access them the same - way regardless of Type 1 or CFF. - - * include/freetype/internal/psaux.h (PS_Builder): Change `TT_Face' - to `FT_Face'. - Remove unused fields. - - * src/psaux/psft.c: Update all accesses of `PS_Builder.face'. - Add some asserts to guard against casting `T1_Face' as `TT_Face'. - - * src/type1/t1objs.h (T1_GlyphSlot): Reorder fields to follow - `CFF_GlyphSlot', so that we can pretend they are the same in the - interpreter. - - * src/psaux/psobjs.c (ps_builder_init, ps_builder_add_point): - Updated with above changes. - -2017-09-25 Ewald Hew - - [psaux] Prepare for Type 1 mode. - - Add some checks for Type 1 data passing through. - - * src/psaux/psfont.h (CF2_Font): Add `isT1' flag. - * src/psaux/psfont.c (cf2_font_setup): Skip the variations and blend - code which is not applicable for Type 1. - - * src/psaux/psft.c (cf2_decoder_parse_charstrings): Avoid accessing - `decoder->cff' in Type 1 mode. - Copy `is_t1' flag to `CF2_Font'. - -2017-09-25 Ewald Hew - - [psaux, cff] Use the new objects. - - * include/freetype/internal/psaux.h, src/psaux/psauxmod.c: Fix - switching between new and old engines. - - * src/cff/cffgload.c, src/cff/cffparse.c: Update calls. - - * src/psaux/psblues.c, src/psaux/psfont.c, src/psaux/psfont.h, - src/psaux/psft.c, src/psaux/psft.h, src/psaux/psintrp.c: Update all - to use new objects. - -2017-09-24 Ewald Hew - - [psaux] Objects for new interpreter (part 2). - - Make the new objects copy over values. They are essentially wrapper - types for the different decoders/builders. - - * include/freetype/internal/psaux.h: Update declarations. - (PS_Builder): Add `is_t1' flag. - (PS_Decoder_{Get,Free}_Glyph_Callback): Renamed to... - (CFF_Decoder_{Get,Free}_Glyph_Callback: ... this. - (PS_Decoder): Updated. - Add `t1_parse_callback' member. - (PSAux_ServiceRec): Add `ps_decoder_init' member. - - * src/psaux/psdecode.h, src/psaux/psobjs.h: Update declarations. - - * src/psaux/psdecode.c, src/psaux/psobjs.c: Implement copy with two - modes. - - * src/psaux/psauxmod.c: Add builder and decoder functions to `PSAux' - service. - -2017-09-24 Ewald Hew - - [psaux] Add objects for new interpreter. - - Introduce `PS_Decoder' and `PS_Builder' which include all fields - from either Type 1 or CFF decoders/builders. - - * include/freetype/internal/psaux.h (PS_Builder, PS_Decoder): New - structs. - - * src/psaux/psobjs.c, src/psaux/psobjs.h: Add `PS_Builder' - functions. - - * src/psaux/psdecode.c, src/psaux/psdecode.h: New files to hold - `PS_Decoder' initialization functions. - - * src/psaux/psaux.c, src/psaux/Jamfile (_sources), - src/psaux/rules.mk (PSAUX_DRV_SRC): Updated. - -2017-09-24 Ewald Hew - - [psaux] Rename files. - - Replace the `cf2' file name prefix with `ps' as the Adobe engine - will be used for both PostScript Types 1 and 2 (CFF) instead of just - CFF. - - s/cf2/ps/ for all following. - - * src/psaux/cf2*: Rename files. - * src/psaux/*: Update includes. - - * src/psaux/Jamfile (_sources), src/psaux/rules.mk (PSAUX_DRC_SRC, - PSAUX_DRV_H): Update file references. - -2017-09-24 Ewald Hew - - [psaux] Minor fix. - - Use `MultiMasters' service in `psaux' instead of a call to `cff'. - The project builds if CFF_CONFIG_OPTION_OLD_ENGINE is not defined. - - * src/psaux/cf2ft.c: Update includes. - (cf2_getNormalizedVector): Use `mm->get_var_blend' instead of - `cff_get_var_blend'. - -2017-09-24 Ewald Hew - - [psaux, cff] Move `cff_random' into `psaux' service. - - NOTE: Does not compile! - - Minor fix to allow both `cff' and `psaux' to use `cff_random'. - - * src/cff/cffload.c (cff_random): Move to... - * src/psaux/psobjs.c: Here. - * src/cff/cffload.h: Move corresponding declaration to - `src/psaux/psobjs.h'. - - * include/freetype/internal/psaux.h (PSAux_ServiceRec): Register the - function here... - * src/psaux/psauxmod.c: And here. - - * src/cff/cffload.c, src/psaux/cf2intrp.c: Update code. - -2017-09-24 Ewald Hew - - [cff] Move struct declarations to `freetype/internal'. - - NOTE: Does not compile! - - This is so that the CFF functions moved to `psaux' can access the - same structs that they need. - - * src/cff/cfftypes.h: Moved to... - * include/freetype/internal/cfftypes.h: ...Here. - - * src/cff/cffobjs.h: Moved the struct declarations to... - * include/freetype/internal/cffotypes.h: ... this new file. - - * include/freetype/internal/internal.h (FT_INTERNAL_CFF_TYPES_H, - FT_INTERNAL_CFF_OBJECT_TYPES_H): New macros. - - * src/cff/cffcmap.h, src/cff/cffdrivr.c, src/cff/cffgload.c, - src/cff/cffgload.h, src/cff/cffload.h, src/cff/cffobjs.c, - src/cff/cffobjs.h, src/cff/cffparse.h, src/psaux/psobjs.h, - include/freetype/internal/psaux.h, - include/freetype/internal/services/svcfftl.h: Update includes. - - * src/cff/rules.mk (CFF_DRV_H): Updated. - -2017-09-24 Ewald Hew - - [psaux, cff] Add new service for inter-module calls. - - NOTE: Does not compile! - - This is to allow CFF functions moved to `psaux' to call functions - declared in `src/cff/cffload.h'. - - * include/freetype/internal/services/svcfftl.h: New file, setting up - a `CFFLoad' service. - - * include/freetype/internal/ftserv.h (FT_DEFINE_SERVICEDESCREC10, - FT_DEFINE_SERVICEDESCREC): New macros. - (FT_SERVICE_CFF_TABLE_LOAD_H): New macro. - - * src/cff/cffdrivr.c, src/cff/cffpic.h: Register the new service. - - * src/cff/cfftypes.h (CFF_FontRec), src/psaux/cf2font.h - (CF2_FontRec): Add service interface. - - * src/cff/cffobjs.c, src/psaux/cf2font.c, src/psaux/cf2ft.c, - src/psaux/cf2intrp.c, src/psaux/cffdecode.c: Use the new service. - -2017-09-24 Ewald Hew - - [psaux, cff] Add callbacks for inter-module calls. - - NOTE: Does not compile! - - * include/freetype/internal/psaux.h: Add function pointer - declarations. - - * src/psaux/cffdecode.c (cff_decoder_init): Update to take in - callbacks. - * src/psaux/cffdecode.h: Ditto. - - * src/cff/cffgload.c (cff_compute_max_advance, cff_slot_load): - Update calls to pass in callbacks. - * src/psaux/cf2ft.c, src/psaux/cffdecode.c: Use them. - -2017-09-24 Ewald Hew - - [psaux, cff] Create new `PSAux' service interface entries. - - NOTE: Does not compile! - - * include/freetype/internal/psaux.h: Include - FT_INTERNAL_TRUETYPE_TYPES_H. - (CFF_Builder_FuncsRec, CFF_Decocer_FuncsRec): New function tables. - (CFF_Builder): Updated. - Fix for forward declaration. - (PSAux_ServiceRec): New field `cff_decoder_funcs'. - - * src/psaux/psauxmod.c (cff_builder_funcs, cff_decoder_funcs): New - function tables. - (PSAux_Interface): Updated. - - * include/freetype/internal/tttypes.h (TT_FaceRec): Add `psaux' - service interface. - - * src/cff/cffgload.c, src/cff/cffobjs.c, src/cff/cffparse.c: Update - function calls to use psaux service. - -2017-09-24 Ewald Hew - - [psaux, cff] Move CFF builder components into `psaux' module. - - NOTE: Does not compile! - - * src/cff/cffgload.c - (cff_builder_{init,done,add_point,add_point1,add_contour,start_point,close_contour}, - cff_check_points): Move to... - * src/psaux/psobjs.c: Here. - - * src/cff/cffgload.h: Move corresponding declarations to - `src/psaux/psobjs.h'. - - * src/cff/cffgload.h (CFF_Builder): Move struct declaration to... - * include/freetype/internal/psaux.h: Here. - -2017-09-24 Ewald Hew - - [psaux, cff] Move CFF decoder components into `psaux' module. - - NOTE: Does not compile! - - * src/cff/cffgload.c (CFF_Operator, - CFF_COUNT_{CHECK_WIDTH,EXACT,CLEAR_STACK}, cff_argument_counts, - cff_operator_seac, cff_compute_bias, - cff_lookup_glyph_by_stdcharcode, - cff_decoder_{parse_charstrings,init,prepare}): Move to... - * src/psaux/cffdecode.c: This new file. - - * src/cff/cffgload.h: Move corresponding declarations to... - * src/psaux/cffdecode.h: This new file. - - * src/cff/cffgload.h (CFF_MAX_{OPERANDS,SUBRS_CALLS,TRANS_ELEMENTS}, - CFF_Decoder_Zone, CFF_Decoder): Move declarations to... - * include/freetype/internal/psaux.h: Here. - - * src/psaux/cf2ft.h: Update include. - - * src/psaux/psaux.c, src/psaux/rules.mk (PSAUX_DRV_SRC): Update with - the new file. - -2017-09-24 Ewald Hew - - [psaux, cff] Move Adobe's engine components into `psaux' module. - - This is the first patch of a sequence to move the Type 2 charstring - processing capability from the `cff' module to the `psaux' module. - - NOTE: Does not compile! - - * src/cff/cf2*: Move these files to... - * src/psaux/cf2*: Here. - - * src/cff/Jamfile (_sources), src/cff/rules.mk (CFF_DRV_SRC, - CFF_DRV_H), src/cff/cff.c, src/cff/cffgload.c: Remove file - references. - - * src/psaux/Jamfile (_sources), src/psaux/rules.mk, src/psaux/psaux.c - (PSAUX_DRV_SRC, PSAUX_DRV_H): Add file references. - -2017-09-24 Alexei Podtelezhnikov - - Tweak per-face LCD filtering controls. - - Thing are simpler with a NULL-function pointer. - - * include/freetype/internal/ftobjs.h (FT_Face_InternalRec): New - pointer to the filter function. - (FT_LibraryRec): Remove unused `lcd_filter'. - (FT_Bitmap_LcdFilterFunc, ft_lcd_filter_fir): Move from here... - * include/freetype/ftlcdfil.h (FT_Bitmap_LcdFilterFunc, - ft_lcd_filter_fir): ... to here. - - * src/base/ftobjs.c (ft_open_face_internal): NULL-initialize the - per-face filter. - (FT_Face_Properties): Set it. - * src/smooth/ftsmooth.c (ft_smooth_render_generic): Simplify. - - * src/base/ftlcdfil.c (ft_lcd_filter_fir, FT_Libary_SetLcdFilter): - Minor. - -2017-09-24 Jonathan Kew - - [sfnt] Fix `premultiply_data' (#52092). - - * src/sfnt/pngshim.c (premultiply_data): Don't use vector extension - if we have less than 16 bytes of data. - -2017-09-24 Werner Lemberg - - [otvalid] Fix handling of ValueRecords. - - For GPOS pair positioning format 1 the description of ValueRecords - in the OpenType specification (1.8.2, from today) is wrong – the - offset has to be taken from the parent structure; in this case the - `PairSet' table. - - * src/otvalid/otvgpos.c (otv_PairSet_validate): Set `extra3'. - (otv_PairPos_validate): Adjust. - -2017-09-23 Werner Lemberg - - [otvalid] Handle `GSUB' and `GPOS' v1.1 tables. - - * src/otvalid/otvgsub.c (otv_GSUB_validate), src/otvalid/otvgpos.c - (otv_GPOS_validate): Implement it. - -2017-09-23 Werner Lemberg - - [otvalid] Update common table handling to OpenType 1.8.2. - - * src/otvalid/otvcommn.c (otv_Device_validate): Handle - VariationIndex subtable. - (otv_Lookup_validate): Handle MarkFilteringSet. - -2017-09-23 Alexei Podtelezhnikov - - [build] Windows-style DLL versioning. - - * build/windows/ftver.rc: New VERSIONINFO resource. - * build/windows/vc2010/freetype.vcxproj: Further improvements. - -2017-09-23 Ben Wagner - - [truetype] Really fix #52082. - - * src/truetype/ttinterp.c (Ins_MDRP): Correct conditional. - -2017-09-23 Werner Lemberg - - [otvalid] Handle `GDEF' v1.2 and v1.3 tables. - - No validation of variation stuff yet. - - * src/otvalid/otvgdef.c (otv_MarkGlyphSets_validate): New function. - (otv_GDEF_validate): Implement it. - -2017-09-22 Werner Lemberg - - [otvalid] Handle `BASE' v1.1 table. - - No validation of variation stuff yet. - - * src/otvalid/otvbase.c (otv_BASE_validate): Implement it. - -2017-09-22 Werner Lemberg - - [otvalid] Macros for 32bit offset support. - - * src/otvalid/otvcommn.h (OTV_OPTIONAL_TABLE32, - OTV_OPTIONAL_OFFSET32, OTV_SIZE_CHECK32): New macros. - -2017-09-21 Alexei Podtelezhnikov - - [build] Simplify Visual C++ 2010 project. - - * build/windows/vc2010/freetype.vcxproj: Remove fake singlethreaded - configurations and tweak. - -2017-09-21 Werner Lemberg - - [truetype] Integer overflow (#52082). - - * src/truetype/ttinterp.c (Ins_MDRP): Avoid FT_ABS. - -2017-09-21 Werner Lemberg - - [sfnt] Fix postscript name for default instance of variation fonts. - - Problem reported by Behdad. - - * src/sfnt/sfdriver.c (sfnt_get_ps_name): Test - `is_default_instance'. - -2017-09-21 Werner Lemberg - - [truetype] Fix `mmvar' array pointers, part 2. - - The previous commit was incomplete. - - * src/truetype/ttgxvar.c: Properly initialize sub-array offsets for - `master' also. - -2017-09-21 Werner Lemberg - - [truetype] Fix `mmvar' array pointers. - - Without this change, clang's AddressSanitizer reports many runtime - errors due to misaligned addresses. - - * src/truetype/ttgxvar.c (TT_Get_MM_Var): Use multiples of pointer - size for sub-array offsets into `mmvar'. - -2017-09-20 Werner Lemberg - - [truetype] Integer overflows. - - Changes triggered by - - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3429 - - * src/truetype/ttinterp.c (Ins_SHPIX, Ins_DELTAP): Use NEG_LONG. - (Ins_MIAP): Use SUB_LONG. - -2017-09-19 Alexei Podtelezhnikov - - [build] Fix DLL builds in Visual C++ project. - - * build/windows/vc2010/freetype.vcxproj: Use DynamicLibrary in Debug - and Release configurations. - * include/freetype/config/ftconfig.h (FT_EXPORT, FT_EXPORT_DEF) - [_DLL]: Use Visual C++ extensions. - -2017-09-19 John Tytgat - - [cff] Fix family name logic of pure CFF fontdata (#52056). - - 1. If `FamilyName' is present in the CFF font, use this for - FT_Face's `family_name'. - 2. Otherwise, use the face name and chop off any subset prefix. - 3. If at this point FT_Face's `family_name' is set, use this - together with the full name to determine the style. - 4. Otherwise, use `CIDFontName' as FT_Face's `family_name'. - 5. If we don't have a valid style, use "Regular". - - Previously, FT_Face's `family_name' entry for pure CFF fontdata - nearly always was the fontname itself, instead of the `FamilyName' - entry in the CFF font (assuming there is one). - - * src/cff/cffobjs.c (cff_face_init) [pure_cff]: Implement it. - -2017-09-18 Alexei Podtelezhnikov - - [build] Declutter Visual C++ 2010-2017 project. - - * build/windows/vc2010/freetype.vcxproj: Use MaxSpeed (/02) - optimization for Release configuration throughout the project. - ---------------------------------------------------------------------------- -Copyright (C) 2017-2019 by +Copyright (C) 2018-2019 by David Turner, Robert Wilhelm, and Werner Lemberg. This file is part of the FreeType project, and may only be used, modified, diff --git a/external/freetype/ChangeLog.29 b/external/freetype/ChangeLog.29 new file mode 100644 index 00000000..21340713 --- /dev/null +++ b/external/freetype/ChangeLog.29 @@ -0,0 +1,2352 @@ +2018-05-01 Werner Lemberg + + * Version 2.9.1 released. + ========================= + + + Tag sources with `VER-2-9-1'. + + * docs/VERSION.TXT: Add entry for version 2.9.1. + * docs/CHANGES: Updated. + + * README, Jamfile (RefDoc), builds/windows/vc2005/freetype.vcproj, + src/base/ftver.rc, builds/windows/vc2005/index.html, + builds/windows/vc2008/freetype.vcproj, + builds/windows/vc2008/index.html, + builds/windows/vc2010/freetype.vcxproj, + builds/windows/vc2010/index.html, + builds/windows/visualc/freetype.dsp, + builds/windows/visualc/freetype.vcproj, + builds/windows/visualc/index.html, + builds/windows/visualce/freetype.dsp, + builds/windows/visualce/freetype.vcproj, + builds/windows/visualce/index.html, + builds/wince/vc2005-ce/freetype.vcproj, + builds/wince/vc2005-ce/index.html, + builds/wince/vc2008-ce/freetype.vcproj, + builds/wince/vc2008-ce/index.html: s/2.9/2.9.1/, s/29/291/. + + * include/freetype/freetype.h (FREETYPE_PATCH): Set to 1. + + * builds/unix/configure.raw (version_info): Set to 22:1:16. + * CMakeLists.txt (VERSION_PATCH): Set to 1. + + * include/freetype/ftgasp.h: Use FT_BEGIN_HEADER and FT_END_HEADER. + +2018-04-26 Werner Lemberg + + Another fix for handling invalid format 2 cmaps. + + Sigh. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8003 + + * src/sfnt/ttcmap.c (tt_cmap2_char_next): Adjust condition to avoid + an endless loop. + +2018-04-24 Ben Wagner + + [base] Avoid undefined behaviour in lcd filtering code (#53727). + + * src/base/ftlcdfil.c (ft_lcd_filter_fir, _ft_lcd_filter_legacy): + Ensure `height > 0'. + +2018-04-22 Werner Lemberg + + * src/base/ftoutln.c (FT_Outline_Decompose): Improve error tracing. + +2018-04-22 Alexei Podtelezhnikov + + [base] Fix bitmap emboldening. + + Bug introduced after release 2.8. + + * src/base/ftbitmap.c (ft_bitmap_assure_buffer): We use + `FT_QALLOC_MULT', which doesn't zero out the buffer. Adjust the + bitmap copying code to take care of this fact. + +2018-04-22 Werner Lemberg + + Another fix for handling invalid format 2 cmaps. + + The previous commit was incomplete. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7928 + + * src/sfnt/ttcmap.c (tt_cmap2_char_next): Adjust condition to avoid + an endless loop. + +2018-04-19 Werner Lemberg + + Fix handling of invalid format 2 cmaps. + + The problem was introduced after the last release. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7828 + + * src/sfnt/ttcmap.c (tt_cmap2_char_next): Avoid endless loop. + +2018-04-17 Werner Lemberg + + [truetype] Integer overflow issues. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7739 + + * src/truetype/ttinterp.c (Ins_CEILING): Use FT_PIX_CEIL_LONG. + +2018-04-16 Werner Lemberg + + [truetype] Integer overflow issues. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7718 + + * src/truetype/ttinterp.c (Ins_MIRP): Use ADD_LONG. + +2018-04-15 Alexei Podtelezhnikov + + [build] Use `info' function of make 3.81. + + * configure, docs/INSTALL, docs/INSTALL.CROSS, docs/INSTALL.GNU, + docs/INSTALL.UNIX, docs/MAKEPP: Bump make version requirements. + + * builds/detect.mk (std_setup): Replace `echo' with `info'. + (dos_setup): Removed. + * builds/unix/install.mk, builds/modules.mk, builds/dos/detect.mk, + builds/windows/detect.mk, builds/os2/detect.mk: Updated. + * builds/newline: No longer needed. + +2018-04-15 Werner Lemberg + + [truetype]: Limit `SLOOP' bytecode argument to 16 bits. + + This fixes + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7707 + + * src/truetype/ttinterp.c (Ins_SLOOP): Do it. + +2018-04-14 Werner Lemberg + + [truetype] Integer overflow issues. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7652 + + * src/truetype/ttinterp.c (Ins_MDAP): Use SUB_LONG. + +2018-04-14 Werner Lemberg + + [autofit] Update to Unicode 11.0.0. + + But no support new scripts (volunteers welcomed). + + * src/autofit/afranges.c (af_arab_nonbase_uniranges, + af_beng_nonbase_uniranges, af_cakm_nonbase_uniranges, + af_deva_nonbase_uniranges, af_geor_uniranges, + af_gujr_nonbase_uniranges, af_mlym_nonbase_uniranges, + af_nkoo_nonbase_uniranges, af_telu_nonbase_uniranges, + af_hani_uniranges): Add new data. + +2018-04-10 Nikolaus Waxweiler + + * CMakeLists.txt, builds/cmake/FindHarfBuzz.cmake: Extensive + modernization measures. + + This brings up the minimum required CMake version to 2.8.12. + + The installation paths follow the GNU defaults now, e.g. installing on a + 64 bit host will place binaries into the lib64/ folder on e.g. Fedora. + + Symbols are hidden by default (e.g. `-fvisibility=hidden' on GCC). + + CMake will no longer look for a C++ compiler. + + Library and .so version now match the Autotools build. + + Comments in the build file and informational messages now use platform + agnostic example commands. + + ftoption.h and ftconfig.h are written directly without a redundant `-new' + copy. + + External dependencies are expressed as option()s and will turn up as such + in cmake-gui. + + Internal: Properties such as dependencies and include directories are now + privately set on the freetype library instead of globally. + + The CPack definitions have been cleaned up, the `make dist' has been + removed. Source packages generated with CPack don't contain Autotools + files and aren't used by the maintainers anyway. + + On Windows, src/base/ftver.rc is compiled to decorate the library with + version and copyright information. + + A pkg-config file is now generated and installed. + +2018-04-09 Werner Lemberg + + [truetype] Integer overflow issues. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7453 + + * src/truetype/ttinterp.c (Round_Super, Round_Super_45): Use + ADD_LONG and SUB_LONG. + +2018-04-06 Alexei Podtelezhnikov + + [windows, wince] Clean up legacy project files. + + * builds/wince/vc2005-ce/freetype.vcproj, + builds/wince/vc2008-ce/freetype.vcproj, + builds/windows/vc2005/freetype.vcproj, + builds/windows/vc2008/freetype.vcproj, + builds/windows/visualce/freetype.vcproj, + builds/windows/visualce/freetype.dsp, + builds/windows/visualc/freetype.vcproj, + builds/windows/visualc/freetype.dsp: Remove per-file compile flags. + +2018-04-04 Werner Lemberg + + [cff, type1] Sanitize `BlueFuzz' and `BlueShift'. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7371 + + * src/cff/cffload.c (cff_load_private_dict): Sanitize + `priv->blue_shift' and `priv->blue_fuzz' to avoid overflows later + on. + + * src/type1/t1load.c (T1_Open_Face): Ditto. + +2018-04-04 Ben Wagner + + * src/truetype/ttobjs.c (trick_names): Add 3 tricky fonts (#53554), + `DFHei-Md-HK-BF', `DFKaiShu-Md-HK-BF' and `DFMing-Bd-HK-BF'. + (tt_check_trickyness_sfnt_ids): Add checksums for 3 tricky fonts + in above. + +2018-04-01 Werner Lemberg + + * builds/toplevel.mk (work): Use $(SEP). + + This fixes the `make refdoc' using Cygwin: $(CAT) is `type' on this + platform, and this program only understands backslashes in paths. + + Reported by Nikhil Ramakrishnan . + +2018-03-30 Werner Lemberg + + [truetype] Fix memory leak (only if tracing is on). + + * src/truetype/ttgxvar.c (TT_Get_MM_Var) [FT_DEBUG_LEVEL_TRACE}: Fix + it. + +2018-03-23 Ben Wagner + + [sfnt] Correctly handle missing bitmaps in sbix format (#53404). + + * src/sfnt/ttfsbit.c (tt_face_load_sbix_image): Fix return value. + +2018-03-23 Ben Wagner + + [truetype] Fix advance of empty glyphs in bitmap fonts (#53393). + + * src/truetype/ttgload.c (TT_Load_Glyph): Apply scaling to metrics + for empty bitmaps. + +2018-03-22 Werner Lemberg + + Remove `ftlcdfil.c' and `ftfntfmt.c' from build files (#53415). + + builds/amiga/makefile, builds/amiga/makefile.os4, + builds/amiga/smakefile, builds/mac/FreeType.m68k_cfm.make.txt, + builds/mac/FreeType.m68k_far.make.txt, + builds/mac/FreeType.ppc_carbon.make.txt, + builds/mac/FreeType.ppc_classic.make.txt, + builds/symbian/freetype.mmp, builds/wince/vc2005-ce/freetype.vcproj, + builds/wince/vc2008-ce/freetype.vcproj, + builds/windows/vc2005/freetype.vcproj, + builds/windows/vc2008/freetype.vcproj, + builds/windows/vc2010/freetype.vcxproj, + builds/windows/vc2010/freetype.vcxproj.filters, + builds/windows/visualc/freetype.dsp, + builds/windows/visualc/freetype.vcproj, + builds/windows/visualce/freetype.dsp, + builds/windows/visualce/freetype.vcproj, vms_make.com: Do it. + +2018-03-13 Werner Lemberg + + * src/sfnt/ttcmap.c (tt_cmap2_validate): Fix potential numeric + overflow. + +2018-03-13 Werner Lemberg + + Fix cmap format 2 handling (#53320). + + The patch introduced for #52646 was not correct. + + * src/sfnt/ttcmap.c (tt_cmap2_char_next): Adjust condition. + +2018-03-10 Nikolaus Waxweiler + + * CMakeLists.txt (BASE_SRCS): Update to changes from 2018-03-05. + +2018-03-09 Chun-wei Fan + + * CMakeLists.txt [win32]: Allow MSVC DLL builds (#53287). + + Do not limit DLL builds to MinGW, since we already have + `__declspec(dllexport)' directives in `ftconfig.h'. + Also suppress more warnings for POSIX functions. + +2018-03-08 Hugh McMaster + + Make installation of `freetype-config' optional (#53093). + + * builds/unix/configure.raw: Add option `--enable-freetype-config' + and set `INSTALL_FT2_CONFIG'. + * builds/unix/unix-def.in (INSTALL_FT2_CONFIG): Define. + * builds/unix/install.mk (install): Handle it. + +2018-03-05 Werner Lemberg + + Make `ftlcdfil.c' part of the `base' module. + + `ftobjs.c' needs `ft_lcd_padding'. + + Problem reported by duhuanpeng <548708880@qq.com>. + + * modules.cfg (BASE_EXTENSIONS): Don't include `ftlcdfil.c'. + + * src/base/ftbase.c: Include `ftlcdfil.c'. + * src/base/rules.mk (BASE_SRC): Add `ftlcdfil.c'. + * src/base/Jamfile (_sources): Adjusted. + + * docs/INSTALL.ANY: Updated. + +2018-03-05 Werner Lemberg + + Make `ftfntfmt.c' part of the `base' module. + + `ftobjs.c' needs `FT_Get_Font_Format'. + + Problem reported by duhuanpeng <548708880@qq.com>. + + * modules.cfg (BASE_EXTENSIONS): Don't include `ftfntfmt.c'. + + * src/base/ftbase.c: Include `ftfntfmt.c'. + * src/base/rules.mk (BASE_SRC): Add `ftfntfmt.c'. + * src/base/Jamfile (_sources): Adjusted. + + * docs/INSTALL.ANY: Updated. + +2018-03-01 Werner Lemberg + + * src/truetype/ttinterp.c (TT_RunIns): Fix tracing arguments. + +2018-02-23 Werner Lemberg + + * builds/unix/configure.raw: Need HarfBuzz 1.3.0 or newer. + + Problem reported by Alan Coopersmith . + +2018-02-17 Werner Lemberg + + [sfnt] Prefer `CBDT'/`CBLC' over `glyf' table (#53154). + +2018-02-06 Werner Lemberg + + [truetype] Integer overflow issues. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=6027 + + * src/truetype/ttinterp.c (Ins_MSIRP, Ins_MIAP, Ins_MIRP): Use + SUB_LONG; avoid FT_ABS. + +2018-02-04 Alexei Podtelezhnikov + + [unix] Use -fvisibility=hidden. + + It is now widely recommended that ELF shared libraries hide symbols + except those with explicit __attribute__((visibility("default"))). + This is supported by all major compilers and should rather be an + option in libtool. + + * builds/unix/configure.raw: Add -fvisibility=hidden to CFLAGS. + * builds/unix/ftconfig.in, builds/vms/ftconfig.h, + include/freetype/config/ftconfig.h (FT_EXPORT): Use visibility + attribute. + +2018-01-27 Werner Lemberg + + [truetype] Better protection against invalid VF data. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=5739 + + Bug introduced in commit 08cd62deedefe217f2ea50e392923ce8b5bc7ac7. + + * src/truetype/ttgxvar.c (TT_Set_Var_Design): Always initialize + `normalizedcoords'. + +2018-01-27 Werner Lemberg + + * src/truetype/ttinterp.c (Ins_GETVARIATION): Avoid NULL reference. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=5736 + +2018-01-27 Werner Lemberg + + * src/truetype/ttgxvar.c (tt_set_mm_blend): Minor. + +2018-01-27 Werner Lemberg + + [truetype] Better trace VF instances. + + * src/truetype/ttgxvar.c (ft_var_to_normalized): Don't emit number + of coordinates. + (TT_Get_MM_Var): Trace instance indices names. + (TT_Set_Var_Design): Updated. + +2018-01-27 Werner Lemberg + + [truetype] Beautify tracing of VF axis records. + + * src/truetype/ttgxvar.c (TT_Get_MM_Var): Show axis records in a + table-like manner. + +2018-01-26 Ben Wagner + + [truetype] Fix multiple calls of `FT_Get_MM_Var' (#52955). + + * src/truetype/ttgxvar.c (TT_Get_MM_Var): Set + `face->blend->num_axis' in case we have to initialize the + `face->blend'. + +2018-01-23 Alexei Podtelezhnikov + + [apinames] Anonymous version map for GNU linker. + + * src/tools/apinames.c (PROGRAM_VERSION): Set to 0.3. + (OutputFormat): Add `OUTPUT_GNU_VERMAP'. + (names_dump): Handle it. + (usage): Updated. + (main): Handle new command line flag `-wL'. + +2018-01-21 Alexei Podtelezhnikov + + [unix] Call libtool to clean up. + + * builds/unix/install.mk (clean_project_unix, distclean_project_unix): + Use libtool. + * builds/freetype.mk: Minor. + +2018-01-18 Alexei Podtelezhnikov + + * src/base/ftver.rc: Fix mingw-w64 compilation. + +2018-01-18 Alexei Podtelezhnikov + + [build] Enable VERSIONINFO resource for Cygwin/MinGW. + + * builds/unix/configure.raw: Check for resource compiler. + * builds/unix/unix-cc.in: Conditionally set up resource compiler. + * builds/freetype.mk: Add conditional rule for `ftver.rc'. + * src/base/ftver.rc: Copyright notice and year update. + +2018-01-18 Alexei Podtelezhnikov + + [build] Move VERSIONINFO resource. + + * builds/windows/vc2010/freetype.vcxproj: Updated. + * builds/windows/ftver.rc: Move file from here... + * src/base/ftver.rc: ... to here. + +2018-01-12 Alexei Podtelezhnikov + + [build] Expand dllexport/dllimport to Cygwin/MinGW. + + * include/freetype/config/ftconfig.h: Respect DLL_EXPORT, + s/_MSC_VER/_WIN32/. + * builds/unix/ftconfig.in: Replicate here. + * builds/vms/ftconfig.h: Replicate here. + +2018-01-12 Alexei Podtelezhnikov + + [build] Improve and document MSVC build. + + * include/freetype/config/ftconfig.h: Guard dllexport/dllimport + attributes with _DLL and FT2_DLLIMPORT. + * builds/windows/vc2010/index.html: Update documentation. + +2018-01-10 Steve Robinson + + * CMakeLists.txt [win32]: Suppress warnings for POSIX functions. + +2018-01-10 Ewald Hew + + [psaux] Correctly handle Flex features (#52846). + + * src/psaux/psintrp.c (cf2_interpT2CharString) : Do not move if doing Flex. + +2018-01-09 Alexei Podtelezhnikov + + * builds/windows/vc2010/freetype.sln: Synchronize with the project. + +2018-01-08 Werner Lemberg + + * Version 2.9 released. + ======================= + + + Tag sources with `VER-2-9'. + + * docs/VERSION.TXT: Add entry for version 2.9. + + * README, Jamfile (RefDoc), builds/windows/vc2005/freetype.vcproj, + builds/windows/vc2005/index.html, + builds/windows/vc2008/freetype.vcproj, + builds/windows/vc2008/index.html, + builds/windows/vc2010/freetype.vcxproj, + builds/windows/vc2010/index.html, + builds/windows/visualc/freetype.dsp, + builds/windows/visualc/freetype.vcproj, + builds/windows/visualc/index.html, + builds/windows/visualce/freetype.dsp, + builds/windows/visualce/freetype.vcproj, + builds/windows/visualce/index.html, + builds/windows/ftver.rc, + builds/wince/vc2005-ce/freetype.vcproj, + builds/wince/vc2005-ce/index.html, + builds/wince/vc2008-ce/freetype.vcproj, + builds/wince/vc2008-ce/index.html: s/2.8.1/2.9/, s/281/29/. + + * include/freetype/freetype.h (FREETYPE_MINOR): Set to 9. + (FREETYPE_PATCH): Set to 0. + + * builds/unix/configure.raw (version_info): Set to 22:0:16. + * CMakeLists.txt (VERSION_PATCH): Set to 0. + +2018-01-07 Werner Lemberg + + Add check for librt, needed for `ftbench' (#52824). + + * builds/unix/configure.raw (LIB_CLOCK_GETTIME): Define; this will + hold `-lrt' if necessary. + + * builds/unix/unix-cc.in (LIB_CLOCK_GETTIME): New variable. + +2018-01-07 Ewald Hew + + [psaux] Fix Type 1 glyphs with too many stem hints. + + According to the CFF specification, charstrings can have up to 96 stem + hints. Due to hint replacement routines in Type 1 charstrings, some + glyphs are rejected by the Adobe engine, which implements the above + limit. This fix turns off hinting for such glyphs. + + * src/psaux/pshints.c (cf2_hintmap_build): Reset the error from calling + `cf2_hintmask_setAll' on a problematic Type 1 charstring and turn off + hinting. + +2018-01-06 Werner Lemberg + + Add `FT_Done_MM_Var'. + + This is necessary in case the application's memory routines differ + from FreeType. A typical example is a Python application on Windows + that calls FreeType compiled as a DLL via the `ctypes' interface. + + * include/freetype/ftmm.h, src/base/ftmm.c (FT_Done_MM_Var): Declare + and define. + + * docs/CHANGES: Updated. + +2018-01-03 Werner Lemberg + + [truetype] Round offsets of glyph components only if hinting is on. + + * src/truetype/ttgload.c (TT_Process_Composite_Component): Implement + it. + +2018-01-03 Werner Lemberg + + * src/truetype/ttgxvar.c (ft_var_to_design): Remove dead code. + + This is a better fix than the previous commit, which is now + reverted. + +2018-01-03 Alexei Podtelezhnikov + + Move internal LCD-related declarations. + + * include/freetype/ftlcdfil.h (ft_lcd_padding, ft_lcd_filter_fir): + Move from here... + * include/freetype/internal/ftobjs.h: ... to here. + +2018-01-03 Alexei Podtelezhnikov + + * include/freetype/config/ftconfig.h (FT_EXPORT, FT_EXPORT_DEF) + [_MSC_VER]: Limit Visual C++ attributes. + +2018-01-03 Werner Lemberg + + [truetype] Make blend/design coordinate round-tripping work. + + Behdad reported that setting blend coordinates, then getting design + coordinates did incorrectly return the default instance's + coordinates. + + * src/truetype/ttgxvar.c (tt_set_mm_blend): Fix it. + +2017-12-31 Werner Lemberg + + * src/sfnt/ttcmap.c (tt_cmap2_char_next): Fix endless loop. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4838 + +2017-12-31 Werner Lemberg + + Synchronize other Windows project files. + + * builds/windows/*: Add missing files. + +2017-12-31 Werner Lemberg + + Update Visual C 2010 project files. + + Problem reported by Hin-Tak. + + * builds/windows/vc2010/freetype.vcxproj: Add files `ftbdf.c' and + `ftcid.c'. + Sort entries. + * builds/windows/vc2010/freetype.vcxproj.filter: Ditto. + Fix members of `FT_MODULE' group. + +2017-12-30 Werner Lemberg + + * builds/vms/ftconfig.h: Synchronize with unix `ftconfig.in' file. + +2017-12-28 Werner Lemberg + + * builds/unix/ftconfig.in: Synchronize with main `ftconfig.h' file. + + Reported by Nikolaus. + +2017-12-27 Werner Lemberg + + Fix compiler warnings. + + * src/base/ftbitmap.c (ft_bitmap_assure_buffer): Make `pitch' and + `new_pitch' unsigned. + + * src/base/ftpsprop.c: Include FT_INTERNAL_POSTSCRIPT_PROPS_H. + +2017-12-27 Werner Lemberg + + Fixes for `make multi'. + + * include/freetype/internal/ftpsprop.h: Use `FT_BASE_CALLBACK'. + (ps_property_get): Harmonize declaration with corresponding + function typedef. + + * include/freety[e/internal/fttrace.h: Add `trace_psprops'. + + * src/base/ftpsprop.c: Include necessary header files. + (FT_COMPONENT): Define. + (ps_property_set): Tag with `FT_BASE_CALLBACK_DEF'. + (ps_property_get): Tag with `FT_BASE_CALLBACK_DEF'. + Harmonize declaration with corresponding function typedef. + +2017-12-27 Werner Lemberg + + Provide support for intra-module callback functions. + + This is needed especially for `make multi' with C++. + + * include/freetype/config/ftconfig.h (FT_BASE_CALLBACK, + FT_BASE_CALLBACK_DEF): New macros. + +2017-12-25 Ewald Hew + + Move PostScript drivers' property handlers to `base'. + + This reduces the amount of duplicated code across PostScript + drivers. + + * src/cff/cffdrivr.c, src/cid/cidriver.c, src/type1/t1driver.c + ({cff,cid,t1}_property_{get,set}): Moved to... + * include/freetype/internal/ftpsprop.h: ...this new file. + (ps_property_{get,set}): New functions to replace moved ones. + + * src/base/ftpsprop.c: New file that implements above functions. + + * include/freetype/internal/internal.h + (FT_INTERNAL_POSTSCRIPT_PROPS_H): New macro. + + * src/cff/cffdrivr.c, src/cid/cidriver.c, src/type1/t1driver.c: + Updated. + + * src/base/Jamfile, src/base/rules.mk (BASE_SRC), src/base/ftbase.c: + Updated. + +2017-12-20 Werner Lemberg + + Speed up FT_Set_Var_{Design,Blend}_Coordinates if curr == new. + + We exit early if the current design or blend coordinates are + identical to the new ones. + + * src/truetype/ttgxvar.c (tt_set_mm_blend, TT_Set_Var_Design): + Implement it, returning internal error code -1 if there will be no + variation change. + + * src/type1/t1load.c (t1_set_mm_blend): Ditto. + + * src/base/ftmm.c (FT_Set_Var_Design_Coordinates, + FT_Set_MM_Blend_Coordinates, FT_Set_Var_Blend_Coordinates): Updated. + +2017-12-18 Werner Lemberg + + [sfnt] Fix charmap type 2 iterator (#52646). + + The subsetted demo font of the report that exhibits the bug has a + very unusual type 2 cmap for Unicode(!): It contains only two + sub-headers, one for one-byte characters (covering the range 0x20 to + 0xFA), and a second one for higher byte 0x01 (just for character + code U+0131). + + Before this commit, the iterator wasn't able to correctly handle a + sub-header for higher byte 0x01. + + * src/sfnt/ttcmap.c (tt_cmap2_char_next): Fix character increment + for outer loop. + +2017-12-18 Matthias Clasen + + [truetype] Fix clamping, minor tracing code beautification. + + * src/truetype/ttgxvar.c (ft_var_to_normalized): Trace number of + design coordinates. + Use clamped value. + +2017-12-18 Werner Lemberg + + * src/*/*: Only use `ft_' and `FT_' variants of stdc library stuff. + +2017-12-18 Werner Lemberg + + * src/truetype/ttgxvar.c (tt_face_vary_cvt): Add size guard (#52688). + +2017-12-18 Werner Lemberg + + [truetype] Fix previous commit. + + * src/truetype/ttgload.c (TT_Process_Simple_Glyph): Correctly handle + unhinted phantom points, which must be properly scaled. + +2017-12-18 Werner Lemberg + + [truetype] Don't apply HVAR and VVAR deltas twice (#52683). + + * src/truetype/ttgload.c (TT_Process_Simple_Glyph): Always adjust + `pp1' to `pp4', except if we have an HVAR and/or VVAR table. + + * src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Handle + alternative code branch identically w.r.t. presence of an HVAR + and/or VVAR table. + +2017-12-17 Jonathan Kew + + [truetype] Correctly handle variation font phantom points (#52683). + + * src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Fix phantom + point indices. + +2017-12-17 Jonathan Kew + + Fix incorrect advance width scaling (#52683). + + * src/base/ftadvance.c (FT_Get_Advances): Always respect the + FT_LOAD_NO_SCALE flag if present. + +2017-12-16 Alexei Podtelezhnikov + + * builds/windows/vc2010/freetype.vcxproj: AfterBuild copy. + * objs/.gitignore: Ignore almost everything. + +2017-12-11 Werner Lemberg + + Fix compiler warning (#52640). + + * src/base/ftbitmap.c (ft_bitmap_assure_buffer): Remove unused + variable. + +2017-12-08 Azzuro + + * builds/windows/vc2010/freetype.vcxproj: Adjust output directory. + + This allows builds with different configurations in parallel. + +2017-12-08 Werner Lemberg + + Fix `make setup dos', second try (#52622). + + * builds/detect.mk (dos_setup): Don't use literal `>' character at + all. Mixing the different escaping rules from make, dos, and + windows is too fragile. + +2017-12-08 Werner Lemberg + + [docmaker] Fix code section parsing. + + Stuff like + + { + + } + + confused the parser, which incorrectly treated `' as a markup + tag. + + * src/tools/docmaker/content.py (ContentProcessor::process_content): + Apply `re_markup_tags' only outside of code sections. + +2017-12-08 Werner Lemberg + + New `ftdriver.h' file, covering all driver modules. + + This reduces redundancy and increases synergy; it also reduces the + number of header files. + + * include/freetype/config/ftheader.h (FT_DRIVER_H): New macro. + (FT_AUTOHINTER_H, FT_CFF_DRIVER_H, FT_TRUETYPE_DRIVER_H, + FT_PCF_DRIVER_H, FT_TYPE1_DRIVER_H): Make them aliases to + FT_DRIVER_H. + + * include/freetype/ftautoh.h, include/freetype/ftcffdrv.h, + include/freetype/ftpcfdrv.h, include/freetype/ftt1drv.h, + include/freetype/ftttdrv.h: Replaced with... + * include/freetype/ftdriver.h: ...this new file. + (FT_CFF_HINTING_ADOBE, FT_T1_HINTING_ADOBE): Renamed to... + (FT_HINTING_ADOBE): ... this new macro. + (FT_CFF_HINTING_FREETYPE, FT_T1_HINTING_FREETYPE): Renamed to... + (FT_HINTING_FREETYPE): ... this new macro. + + * src/*/*: Updated accordingly. + +2017-12-08 Werner Lemberg + + Move `ftdriver.h' to `ftdrv.h'. + + * include/freetype/internal/ftdriver.h: Renamed to... + * include/freetype/internal/ftdrv.h: ... this name. + + * include/freetype/internal/internal.h (FT_INTERNAL_DRIVER_H): + Updated. + +2017-12-08 Werner Lemberg + + Fix access to uninitalized memory (#52613). + + Also reported as + + https://bugs.chromium.org/p/chromium/issues/detail?id=791317 + + * src/base/ftbitmap.c (ft_bitmap_assure_buffer): If increasing the + bitmap size needs a larger bitmap buffer, assure that the new memory + areas are initialized also. + +2017-12-08 Werner Lemberg + + Fix `make setup dos' (#52622). + + * builds/detect.mk (dos_setup): Properly escape literal `>' + character. + +2017-12-07 Werner Lemberg + + Fix C++ compilation. + + * src/psaux/psauxmod.h: Use FT_CALLBACK_TABLE macro where necessary. + + * src/smooth/ftsmooth.c (ft_smooth_render_generic): Fix warning. + +2017-12-07 Werner Lemberg + + Fix `make multi'. + + * include/freetype/internal/fttrace.h: Remove unused tracing macros. + s/pshalgo2/pshalgo/. + Add `trace_cffdecode'. + * src/pshinter/pshalgo.c (FT_COMPONENT): Updated. + + * src/cff/cffload.c: Include FT_INTERNAL_POSTSCRIPT_AUX_H. + * src/cff/cffobjs.c: Include FT_SERVICE_METRICS_VARIATIONS_H and + FT_SERVICE_CFF_TABLE_LOAD_H. + + * src/cid/cidriver.c: Include FT_INTERNAL_POSTSCRIPT_AUX_H. + + * src/psaux/cffdecode.c: Include FT_FREETYPE_H and + FT_INTERNAL_DEBUG_H. + (FT_COMPONENT): Define. + * src/psaux/cffdecode.h: Include FT_INTERNAL_POSTSCRIPT_AUX_H. + * src/psaux/psauxmod.h: Include FT_INTERNAL_POSTSCRIPT_AUX_H. + Declare `cff_builder_funcs' and `ps_builder_funcs'. + * src/psaux/psft.c: Include `psobjs.h' and `cffdecode.h'. + * src/psaux/psobjs.c : Include `psauxmod.h'. + +2017-12-07 Werner Lemberg + + * include/freetype/config/ftheader.h: Some clean-up. + + This commit removes documentation of deprecated macros and does some + minor streamlining. + +2017-12-06 Werner Lemberg + + * builds/symbian/bld.inf: Updated. + +2017-12-06 Werner Lemberg + + New header file `ftparams.h' that collects all parameter tags. + + * include/freetype/config/ftheader.h (FT_PARAMETER_TAGS_H): New + macro. + (FT_TRUETYPE_UNPATENTED_H, FT_UNPATENTED_HINTING_H): Define it to + `ftparams.h'. + + * include/freetype/ftautoh.h, include/freetype/ftcffdrv.h, + include/freetype/ftincrem.h, include/freetype/ftlcdfil.h, + include/freetype/ftsnames.h, include/freetype/ftt1drv.h: Include + FT_PARAMETER_TAGS_H. + Move FT_PARAM_TAG_XXX definitions to... + * include/freetype/ftparams.h: ...this new file. + + * include/freetype/ttunpat.h: Remove. No longer needed. + +2017-12-05 Werner Lemberg + + Improve tracing messages by using singular and plural forms. + + * src/*/*.c: Implement it. + +2017-12-04 Werner Lemberg + + [truetype] Allow shared points in `cvar' table (#52532). + + * src/truetype/ttgxvar.c (tt_face_vary_cvt): Implement it by copying + and adjusting the corresponding code from + `TT_Vary_Apply_Glyph_Deltas'. + +2017-11-28 Werner Lemberg + + [truetype] Improving tracing of composite glyphs. + + * src/truetype/ttgload.c (TT_Load_Composite_Glyph) + [FT_DEBUG_LEVEL_TRACE]: Show composite glyph information. + +2017-11-27 Werner Lemberg + + [type1] Allow (again) `/Encoding' with >256 elements (#52464). + + In version 2.6.1, this has been disallowed to better reject + malformed fonts; however, this restriction was too strong. This + time, we only take the first 256 elements into account, since + encoding arrays are always accessed with a 8bit integer, according + to the PostScript Language Reference. + + * src/type1/t1load.c (parse_encoding): Implement it. + +2017-11-27 Jan Alexander Steffens (heftig) + + Fix last commit (#52522). + + * builds/freetype.mk: Set `FT_OPTION_H' and `FTOPTION_FLAG' + properly if we have `ftoption.h' in `BUILD_DIR'. + +2017-11-24 Werner Lemberg + + [unix] Install a massaged `ftoption.h' file (#51780). + + * builds/unix/configure.raw (ftoption_set, ftoption_unset): New + auxiliary functions to construct... + (FTOPTION_H_SED): ... this new variable. + Apply it as a sed argument while copying `ftoption.h' to the + `builds/unix' directory (using `AC_CONFIG_FILES'). + Simplify code of test that checks cpp's computation of bit length + (the test previously created an empty `ftoption.h' file and deleted + it immediately afterwards); without this change, it can happen on my + GNU/Linux box that `configure's execution of `config.status' doesn't + create `ftoption.h' (no idea why this happens). + + * builds/unix/install.mk (install): Install + `builds/unix/ftoption.h'. + + * builds/unix/unix-def.in (DISTCLEAN): Updated. + + * builds/unix/.gitignore: Updated. + +2017-11-23 Tor Andersson + + Silence unused function warnings (#52465). + + Some static function declarations cause unused function warnings if + certain config options are turned off via `ftoption.h'. + + * src/base/ftbase.h, src/base/ftrfork.c, src/sfnt/ttbdf.h, + src/truetype/ttgxvar.h: Add #ifdef guards around these sections. + +2017-11-22 Ewald Hew + + * src/psaux/psft.c (cf2_setGlyphWidth): Check format before setting. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4377 + +2017-11-22 Ewald Hew + + [psaux] Fix CFF advance widths. (#52466) + + Glyph advance widths were being written to the new `PS_Decoder' but not + saved to the underlying format specific decoder. This caused pure CFF + fonts to have bad advance width. + + * include/freetype/internal/psaux.h (PS_Decoder): Change `glyph_width' + field to pointer. + Remove unused fields. + * src/psaux/psobjs.c (ps_decoder_init): Change `glyph_width' from copy + to reference. + Remove unused. + * src/psaux/psft.c (cf2_setGlyphWidth): Update code. + +2017-11-15 Vlad Tsyrklevich + + * include/freetype/ftrender.h: Fix `FT_Renderer_RenderFunc' type. + +2017-11-14 Nikolaus Waxweiler + + Use Adobe hinting engine for `light' hinting of both CFF and Type 1. + + Since Ewald Hew factored the Adobe hinting engine out of the CFF + driver code, we can now use it on Type 1 (and CID) font formats, as + both have the same hinting philosophy. + + This change activates the Adobe hinter when in LIGHT mode, and + therefore always unless explicitly asking for the auto-hinter. This + makes LIGHT behavior consistent with CFF fonts. As of this commit, + the hinting engine table looks as follows. + + LIGHT NORMAL + ------------------------- + TrueType Auto v40 + CFF Adobe Adobe + Type 1 Adobe Adobe + +2017-11-10 Yuri Levchenko + + * CMakeLists.txt: Add `DISABLE_FORCE_DEBUG_PREFIX' option. + +2017-11-06 Alexei Podtelezhnikov + + * src/base/ftobjs.c (FT_Load_Glyph): Relocate condition. + +2017-11-06 Alexei Podtelezhnikov + + * src/smooth/ftgrays.c (gray_set_cell): Fix uninitialized variables. + +2017-11-03 Ewald Hew + + [psaux] Fix PostScript interpreter rewinding in Type 1 mode. (#52251) + + The interpreter in Type 1 mode rewinds the charstring after collecting + all hints for building the initial hintmap (commit d52dd7f). However, + some charstrings use `endchar' in a final subroutine call, rewinding to + the start of that subroutine, and only a small section of the actual + glyph is drawn. + + * src/psaux/psintrp.c (cf2_interpT2CharString) : + Ensure we are on the top level charstring before rewinding. + +2017-11-03 suzuki toshiya + + [truetype] Add more tricky fonts. + + See the report by Yang Yinsen. + https://lists.gnu.org/archive/html/freetype-devel/2017-11/msg00000.html + + * src/truetype/ttobjs.c (trick_names): Add `DFGothic-EB', + `DFGyoSho-Lt', `DFHSGothic-W5', `DFHSMincho-W3' and `DFHSMincho-W7'. + (tt_check_trickyness_sfnt_ids): Add checksums for DFGothic-EB, + DFGyoSho-Lt, DFHSGothic-W5, DFHSMincho-W3 and DFHSMincho-W7. Also + add checksums for DLCLiShu and DLCHayBold which their family names + were already listed but their checksums were previously unknown. + +2017-11-01 Alexei Podtelezhnikov + + [smooth] Fix complex rendering at high ppem. + + We used to split large glyphs into horizontal bands and continue + bisecting them still horizontally if that was not enough. This is + guaranteed to fail when a single scanline cannot fit into the + rendering memory pool. Now we bisect the bands vertically so that + the smallest unit is a column of the band height, which is guranteed + to fit into memory. + + * src/smooth/ftgrays.c (gray_convert_glyph): Implement it. + +2017-10-20 Alexei Podtelezhnikov + + [smooth] Improve complex rendering at high ppem. + + At large sizes almost but not exactly horizontal segments can quickly + drain the rendering pool. This patch at least avoids filling the pool + with trivial cells. Beyond this, we can only increase the pool size. + + Reported, analyzed, and tested by Colin Fahey. + + * src/smooth/ftgrays.c (gray_set_cell): Do not record trivial cells. + +2017-10-20 Alexei Podtelezhnikov + + [base] Improve tracing in FT_Load_Glyph, FT_*_Size. + + * src/base/ftobjs.c (FT_Load_Glyph): Tag tracing messages with + function name, glyph index, and load flags. + (FT_Select_Metrics, FT_Request_Metrics): Remove all tracing. + (FT_Select_Size, FT_Request_Size): Improve tracing. + +2017-10-18 Alexei Podtelezhnikov + + [base] Improve tracing in FT_Render_Glyph. + + * src/base/ftobjs.c (FT_Render_Glyph_Internal): Add total coverage + calculations and downgrade Netpbm dump to bitmap:7. + +2017-10-15 Ewald Hew + + [cff] Fix segfault on missing `psaux' (#52218) + + * src/cff/cffload.c (cff_done_blend): Add a check for possible nullptr. + + * modules.cfg: Update dependency list. + +2017-10-15 Alexei Podtelezhnikov + + [base, cff] Fix MSVC warnings. + + * src/base/ftobjs.c (FT_New_Library): C4702: unreachable code. + (ft_glyphslot_preset_bitmap): C4244: possible loss of data. + * src/cff/cffload.c (cff_blend_doBlend): C4244: possible loss of data. + Turn `sum' into unsigned. + +2017-10-14 Alexei Podtelezhnikov + + [base] Netpbm image tracing. + + * src/base/ftobjs.c (FT_Load_Glyph): Trace bitmap size. + (FT_Render_Glyph_Internal): Trace bitmap in Netpbm format. + + * src/smooth/ftgrays.c (gray_sweep): Sweep remnants of span tracing. + +2017-10-14 Alexei Podtelezhnikov + + * builds/windows/ftdebug.c (FT_Message): Print to stderr. + * builds/wince/ftdebug.c (FT_Message): Ditto. + +2017-10-14 Behdad Esfahbod + + [afshaper] Delay creating `hb_set' objects until needed. + + In runs on Noto Naskh Arabic, this results in 89 sets created + instead of 340 before. Makes auto-hinter setup with HarfBuzz + enabled 20% to 30% faster. + + * src/autofit/afshaper.c (af_shaper_get_coverage): Implement it. + +2017-10-12 Ewald Hew + + [type1, cid] Add hinting engine switch. + + Implement property service in `type1' and `cid' drivers to allow + switching between FreeType or Adobe hinting engine when both are + available. + + * src/cid/cidriver.c (cid_property_{set,get}, cid_services), + src/type1/t1driver.c (t1_property_{set,get}, t1_services): Add + Properties service. + + * src/cid/cidobjs.c (cid_driver_init), src/type1/t1objs.c + (T1_Driver_Init): Add default property values. + +2017-10-12 Ewald Hew + + Add T1_CONFIG_OPTION_OLD_ENGINE configuration option. + + This controls whether the old Type 1 engine gets compiled into FreeType. + It is disabled by default. + + * devel/ftoption.h, include/freetype/config/ftoption.h + (T1_CONFIG_OPTION_OLD_ENGINE): New macro. + + * include/freetype/internal/psaux.h (PS_Decoder): Remove unused field. + * include/freetype/internal/psaux.h, src/cid/cidgload.c + (cid_load_glyph), src/psaux/psauxmod.c, src/psaux/psobjs.c + (ps_builder_add_point), src/psaux/t1decode.c + (t1_lookup_glyph_by_stdcharcode, t1_decoder_parse_glyph, + t1operator_seac, t1_decoder_parse_charstrings), src/psaux/t1decode.h, + src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Surround + relevant code with macro. + Minor code changes. + +2017-10-12 Ewald Hew + + Extract width parsing from Type 1 parser. + + Duplicate the fast advance width calculations from the old parser. + This is to facilitate adding options for compiling out the old parser. + + * src/psaux/t1decode.{c,h} (t1_decoder_parse_metrics): New function. + * include/freetype/internal/psaux.h (T1_Decoder_Funcs): New entry + `parse_metrics'. + * src/psaux/psauxmod.c: Set the new entry. + + * src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String), + src/cid/cidgload.c (cid_load_glyph): Separate + conditional for selecting engine. + +2017-10-09 Werner Lemberg + + * src/base/ftoutln.c (FT_Outline_Translate): Fix integer overflow. + + Reported as + + https://bugs.chromium.org/p/chromium/issues/detail?id=772775 + +2017-10-08 Werner Lemberg + + * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Integer overflows. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3579 + +2017-10-07 Werner Lemberg + + [sfnt] Adjust behaviour of PS font names for variation fonts. + + * src/sfnt/sfdriver.c (sfnt_get_var_ps_name): Use a named instance's + PS name only if no variation is applied. + +2017-10-07 Werner Lemberg + + [cff, truetype] Adjust behaviour of named instances. + + This commit completely separates the interaction between named + instances and variation functions. In particular, resetting the + variation returns to the current named instance (if set) and not to + the base font. + + As a side effect, variation functions no longer change the named + instance index. + + * src/cff/cffobjs.c (cff_face_init): Use MM service's `set_instance' + function. + Also apply `MVAR' table to named instances. + + * src/truetype/ttgxvar.c (TT_Get_MM_Var): Add cast. + (tt_set_mm_blend): No longer check whether requested variation + coincides with a named instance. + (TT_Set_Var_Design): Use current named instance for default + coordinates. + * src/truetype/ttobjs.c (tt_face_init): Use `TT_Set_Named_Instance'. + +2017-10-07 Werner Lemberg + + Make `FT_Set_Named_Instance' work. + + * src/cff/cffdrivr.c (cff_set_instance): New function. + (cff_service_multi_masters): Register it. + + * src/truetype/ttgxvar.c (TT_Set_Named_Instance): New function. + * src/truetype/ttgxvar.h: Updated. + * src/truetype/ttdriver.c (tt_service_gx_multi_masters): Register + it. + + * src/type1/t1load.c (T1_Reset_MM_Blend): New function. + * src/type1/t1load.h: Updated. + * src/type1/t1driver.c (t1_service_multi_masters): Register it. + +2017-10-07 Werner Lemberg + + Make `FT_FACE_FLAG_VARIATION' work. + + * include/freetype/internal/tttypes.h (TT_Face): Remove + `is_default_instance'; this can be replaced with a combination of + `FT_IS_VARIATION' and `FT_IS_INSTANCE'. + + * src/cff/cffdrivr.c (cff_get_advances): Updated. + + * src/sfnt/sfdriver.c (sfnt_get_ps_name), src/sfnt/sfobjs.c + (sfnt_init_face): Updated. + + * src/truetype/ttdriver.c (tt_get_advances), src/truetype/ttgload.c + (TT_Process_Simple_Glyph, load_truetype_glyph, IS_DEFAULT_INSTANCE), + src/truetype/ttgxvar.c (tt_set_mm_blend): Updated. + * src/truetype/ttgxvar.c (TT_Set_MM_Blend, TT_Set_Var_Design): + Handle `FT_FACE_FLAG_VARIATION'. + + * src/type1/t1load.c (T1_Set_MM_Blend, T1_Set_MM_Design): Handle + `FT_FACE_FLAG_VARIATION'. + +2017-10-07 Werner Lemberg + + New function `FT_Set_Named_Instance'. + + No effect yet. + + * src/base/ftmm.c (FT_Set_Named_Instance): New function. + + * include/freetype/ftmm.h: Updated. + +2017-10-07 Werner Lemberg + + Add macros for checking whether a font variation is active. + + * include/freetype/freetype.h (FT_FACE_FLAG_VARIATION, + FT_IS_VARIATION): New macros. + No effect yet. + +2017-10-07 Werner Lemberg + + Add framework for setting named instance in MM service. + + * include/freetype/internal/services/svmm.h (FT_Set_Instance_Func): + New function typedef. + (MultiMasters): Add `set_instance' member. + (FT_DEFINE_SERVICE_MULTIMASTERSREC): Updated. + + * src/cff/cffdrivr.c (cff_service_multi_masters), + src/truetype/ttdriver (tt_service_gx_multi_masters), + src/type1/t1driver.c (t1_service_multi_masters): Updated. + +2017-10-07 Werner Lemberg + + [type1] Minor code shuffling. + + * src/type1/t1load.c (T1_Set_MM_Blend): Make it a wrapper of... + (t1_set_mm_blend): ...this new function. + (T1_Set_MM_Design): Use `t1_set_mm_blend'. + +2017-10-05 Werner Lemberg + + * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Fix integer + overflow. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3539 + +2017-10-05 Werner Lemberg + + Fix compiler warnings. + + * src/cff/cffdrivr.c (cff_ps_get_font_extra): Avoid code that relies + on numeric overflow. + Add cast. + + * src/smooth/ftsmooth.c (ft_smooth_render_generic): Fix variable + types, add cast. + +2017-10-04 John Tytgat + + [cff] Add support for `FSType'. + + * include/freetype/internal/cfftypes.h (CFF_FontRec): Add + `font_extra' entry. + + * src/cff/cffdrivr.c (cff_ps_get_font_extra): New function to + retrieve FSType info from the embedded PostScript data. + (cff_service_ps_info): Register function. + + * src/cff/cffload.c (cff_font_done): Free `font_extra'. + +2017-09-30 Alexei Podtelezhnikov + + Signedness fixes in bitmap presetting. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3514. + + * src/raster/ftrend1.c (ft_raster1_render): Explicitly signed height. + * src/smooth/ftsmooth.c (ft_smooth_render_generic): Ditto. + * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Explicitly unsigned + subtraction. + +2017-09-29 Alexei Podtelezhnikov + + Bitmap metrics presetting [2/2]. + + * src/base/ftobjs.c (FT_Load_Glyph): Preset the bitmap metrics when + appropriate but `FT_Render_Glyph' is not called. + * include/freetype/freetype.h (FT_GlyphSlotRec): Document the change. + +2017-09-28 Alexei Podtelezhnikov + + [smooth, raster] Miscellaneous cleanups. + + * src/raster/ftrend1.c (ft_raster1_render): Clean up the exit. + * src/smooth/ftsmooth.c (ft_smooth_render_generic): Reduce + translations and clean up the exit. + (ft_smooth_render_lcd, ft_smooth_render_lcd): Remove unused `error'. + +2017-09-28 Ben Wagner + + [truetype] Really, really fix #52082. + + * src/truetype/ttinterp.c (Ins_MDRP): Correct conditional. + +2017-09-28 Werner Lemberg + + * src/psaux/psintrp.c (cf2_doStems): Fix integer overflow. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3510 + +2017-09-28 Ewald Hew + + * src/cid/cidgload.c (cid_slot_load_glyph): Fix memory leak. + + Reported as + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3489 + +2017-09-28 Alexei Podtelezhnikov + + Bitmap metrics presetting [1/2]. + + This mainly just extracts the code for presetting the bitmap metrics + from the monochrome, grayscale, and LCD renderers into a separate + function. + + * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): New function that + calculates prospective bitmap metrics for the given rendering mode. + * include/freetype/internal/ftobjs.h (ft_glyphslot_preset_bitmap): + Declare it. + + * src/base/ftlcdfil.c (ft_lcd_padding): New helper function that adds + padding to CBox taking into account pecularities of LCD rendering. + * include/freetype/ftlcdfil.h (ft_lcd_padding): Declare it. + + * src/raster/ftrend1.c (ft_raster1_render): Reworked to use + `ft_glyphslot_preset_bitmap'. + * src/smooth/ftsmooth.c (ft_smooth_render_generic): Ditto. + (ft_smooth_render_lcd, ft_smooth_render_lcd): The pixel_mode setting + is moved to `ft_glyphslot_preset_bitmap'. + +2017-09-28 Ewald Hew + + [psaux] Fix compiler warning. + + * src/psaux/pshints.c (cf2_hintmap_dump): Add switch for tracing + code. + +2017-09-27 Werner Lemberg + + * src/sfnt/ttload.c (tt_face_load_font_dir): Fix compiler warning. + +2017-09-25 Werner Lemberg + + [psaux] Fix compiler warnings. + + * src/psaux/psft.c (cf2_initLocalRegionBuffer): Remove redundant + test. + + * src/psaux/psintrp.c (cf2_interpT2CharString) + : Add casts. + + * src/psaux/psobjs.c (ps_decoder_init): Add cast. + +2017-09-25 Ewald Hew + + [psaux] Minor fixes. + + * include/freetype/internal/psaux.h, src/psaux/psobjs.{c,h}: + Rearrange `ps_builder_init' arguments to conventional order. + + * src/psaux/psft.c (cf2_decoder_parse_charstrings): Add a check and + notice for `SubFont' in Type 1 mode. + +2017-09-25 Ewald Hew + + [psaux] Move `psdecode' into `psobjs'. + + As the former only contains a single procedure, move it into + `psobjs' for simplicity. Also change the parameter order to the + conventional one. + + * src/psaux/psdecode.c (ps_decoder_init): Moved to... + * src/psaux/psobjs.c: ...Here. + * src/psaux/psdecode.h, src/psaux/psobjs.h: Ditto. + + * include/freetype/internal/psaux.h (PSAux_ServiceRec): Update + `ps_decoder_init' function signature. + + * src/cff/cffgload.c, src/cid/cidgload.c, src/type1/t1gload.c: + Update calls. + + * src/psaux/psaux.c, src/psaux/psauxmod.c: Update includes. + + * src/psaux/Jamfile (_sources), src/psaux/rules.mk (PSAUX_DRV_SRC): + Update file references. + +2017-09-25 Ewald Hew + + [psaux] Fix Type 1 hinting. + + Type 1 hinting breaks sometimes when mid-charstring hints should + have been in the initial hintmap. This fix adds a preprocessing + pass that reads all hints and builds the correct initial hintmap + first, before proceeding to build the glyph outline. + + * src/psaux/psintrp.c (cf2_interpT2CharString): New + `initial_map_ready' boolean flag. + Ignore outline commands and hint changes on first pass. + : Add section to build hintmap and rewind. + +2017-09-25 Ewald Hew + + [psaux] Add tracing for hints. + + * src/psaux/pshints.c (cf2_hintmap_dump): New function. + (cf2_hintmap_insertHint): Trace incoming and inserted hints. + (cf2_hintmap_build): Dump hintmap before and after hint adjustment. + +2017-09-25 Ewald Hew + + [psaux] Minor fixes. + + * src/psaux/psintrp.c (cf2_interpT2CharString): Fix check for pop + results. + s/font->decoder/decoder/ where necessary. + : Use + offset parameter in `cf2_doStems' instead of doing correction for + left-sidebearing. + +2017-09-25 Ewald Hew + + [cid] Use the new engine. + + * src/cid/cidgload.c: Update includes. + (cid_load_glyph, cid_slot_load_glyph): Implement changes to glyph + loading code as with `type1' module. + +2017-09-25 Ewald Hew + + [cid] Add Adobe engine configuration. + + This is similar to what was done in the `type1' module. + + * src/cid/cidriver.c (t1cid_driver_class): Update declaration. + * src/cid/cidobjs.c: Include FT_TYPE1_DRIVER_H. + (cid_driver_init): Update code. + +2017-09-25 Ewald Hew + + [psaux] Change subfont synthesis for CID fonts. + + Change `t1_make_subfont' to take in the Private dict record as an + argument. This is because Type 1 and CID font records in FreeType + have this in different places. + + * src/psaux/psobjs.c (t1_make_subfont): Change `T1_Face' to + `FT_Face' so that CID is also accepted. + Take `PS_Private' as an argument and let caller figure out where the + Private dict actually is. + Update references. + + * include/freetype/internal/psaux.h, src/psaux/psobjs.h: Update + declaration. + + * src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Update + call. + +2017-09-25 Ewald Hew + + [type1] Switch to Adobe engine. + + * src/type1/t1objs.c (T1_Driver_Init): Set default to Adobe engine. + +2017-09-25 Ewald Hew + + [psaux] Extend Adobe interpreter (seac). + + This concludes the changes needed to add Type 1 support. + + * src/psaux/psintrp.c: Update includes. + (cf2_interpT2CharString) : Implement this similarly to + implied seac for CFF. + + * src/psaux/t1decode.c (t1_lookup_glyph_by_stdcharcode_ps): New + function to look up the glyph index. + + * src/psaux/psft.c (cf2_getT1SeacComponent, + cf2_freeT1SeacComponent): New functions to get the charstrings for + seac components. + + * src/psaux/t1decode.h, src/psaux/psft.h: Update declarations. + +2017-09-25 Ewald Hew + + [psaux] Extend Adobe interpreter (flex in callothersubr). + + * src/psaux/psintrp.c (cf2_interpT2CharString) + : Fix Flex feature handling (OtherSubrs 0, 1, + 2). + : Do not actually move the `glyphPath' while doing + flex. This is to avoid closing the current contour. + +2017-09-25 Ewald Hew + + [psaux] Extend Adobe interpreter (callothersubr). + + * src/psaux/psintrp.c (cf2_interpT2CharString) + : Copy code from + `t1_decoder_parse_charstrings' (in `t1decode.c'). + OtherSubr 3 (change hints) should reset the hintmask, so that the + new hints are applied. + Fix function calls and stack access. + +2017-09-25 Ewald Hew + + [psaux] Extend Adobe interpreter (pop). + + * src/psaux/psintrp.c (cf2_interpT2CharString): Change how unhandled + OtherSubr results are stored. Implement the PostScript stack using + an array. + : Ensure that the stack is not cleared after getting + `OtherSubr' results. + Fix stack access. + +2017-09-25 Ewald Hew + + [psaux] Extend Adobe interpreter (callsubr). + + * src/psaux/psintrp.c (cf2_interpT2CharString) : + Type 1 mode. + + * src/psaux/psft.c (cf2_initLocalRegionBuffer): Add Type 1 mode. + +2017-09-25 Ewald Hew + + [psaux] Extend Adobe interpreter (div, four-byte numbers). + + * src/psaux/psintrp.c (cf2_interpT2CharString) : Add + Type 1 mode. Type 1 requires large integers to be followed by + `div'; cf. `Adobe Type 1 Font Format', section 6.2. + : Push Type 1 four-byte numbers as `Int' always. This is + to ensure `div' and `callsubr' get values they can use. + +2017-09-25 Ewald Hew + + [psaux] Extend Adobe interpreter (hints). + + * src/psaux/psintrp.c (cf2_interpT2CharString) : Add correction for left sidebearing in Type 1 mode. + Allow adding hints mid-charstring. + : Translate into equivalent commands + for three normal stem hints. This requires some recalculation of + stem positions. + Correction for left sidebearing. + +2017-09-25 Ewald Hew + + [psaux] Extend Adobe interpreter (hsbw, sbw). + + * src/psaux/psintrp.c (cf2_doStems): `hsbw' or `sbw' must be the + first operation in a Type 1 charstring. + (cf2_interpT2CharString): Remove unused variables. + : `hsbw' or `sbw' + must be the first operation in a Type 1 charstring. + : Fix data access and add correction for + left sidebearing. + +2017-09-25 Ewald Hew + + [psaux] Extend Adobe interpreter (setcurrentpoint). + + * src/psaux/psintrp.c (cf2_interpT2CharString) + : Fix stack access. + +2017-09-25 Ewald Hew + + [psaux] Extend Adobe interpreter (closepath). + + * src/psaux/psintrp.c (cf2_interpT2CharString) : + Use the right builder function. We can use the `haveWidth' boolean + already present, instead of implementing `parse_state'. + +2017-09-25 Ewald Hew + + [psaux] Add Type 1 operations to Adobe CFF interpreter. + + The following Type 1 specific ops have been added (copied from + `t1decode'): + + closepath + vstem3 + hstem3 + seac + sbw + callothersubr + pop + setcurrentpoint + hsbw + + The following require a Type 1 mode, because of differences in + specification: + + hstem + vstem + vmoveto + callsubr + div + rmoveto + hmoveto + Numbers + + The subsequent commits will implement these changes and adapt + accesses of data and objects to the new interpreter. + + NOTE: Will not compile in the meantime! + + * src/psaux/psintrp.c: Add opcodes to enum. + (cf2_interpT2CharString): Copy relevant code over from + `t1_decoder_parse_charstrings' (in `t1decode.c'). + +2017-09-25 Ewald Hew + + [type1] Fixes for rendering. + + The Type 1 advance width calculation passes null for glyph slot, + etc, which can cause null pointer access in the new interpreter. + Fall back to the old one for now. + + Fix the large glyph retry code and ensure hinting and scaling flags + are set properly. + + * src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Add a + check for metrics_only. + Set the `force_scaling' flag. + (T1_Parse_Glyph): Updated. + (T1_Load_Glyph): Add `hinting' and `scaled' flags. + +2017-09-25 Ewald Hew + + [psaux] Add missing objects (2/2). + + Synthesize a `SubFont' object for Type 1 fonts. This is used in the + interpreter to access Private dict data, which are stored in + different places for Type 1 and CFF. This allows the same data to + be used in either mode. + + * src/psaux/psobjs.c (t1_make_subfont): New procedure to copy + required values to a dummy `CFF_SubFont' object. This is similar to + `cff_make_private_dict'. + * src/psaux/psobjs.h: Add the new declaration. + + * include/freetype/internal/psaux.h, src/psaux/psauxmod.c: Ditto. + Add this to the PSAux Service for future use with CID fonts. + + * src/type1/t1gload.c: Include FT_INTERNAL_CFF_TYPES_H. + (T1_Parse_Glyph_And_Get_Char_String): Add the call. + +2017-09-25 Ewald Hew + + [psaux] Add missing objects for Type 1 (1/2). + + Move `CF2_Font' instance to `PS_Decoder'. This is the context for + the interpreter and since it is currently stored in `CFF_Font', is + unavailable in Type 1 mode. + + * include/freetype/internal/psaux.h (T1_Decoder, PS_Decoder): New + `cf2_instance' field. + + * src/psaux/psdecode.c (ps_decoder_init): Copy `cf2_instance' to + `PS_Decoder'. + + * src/psaux/t1decode.c (t1_decoder_done): Add finalization code. + + * src/psaux/psft.c (cf2_decoder_parse_charstrings): Update accesses. + +2017-09-25 Ewald Hew + + Allow `type1' module to use the Adobe engine. + + Add the callback and some conditionals to switch between the two + engines. + + * include/freetype/internal/psaux.h (T1_Decoder_FuncsRec): Change + function declarations. + * src/psaux/psauxmod.c (T1_Decoder_FuncsRec): Register the + callbacks. + + * src/psaux/psobjs.c (ps_builder_add_point): Add conditionals for + number conversion. + + * src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Add code + to choose which renderer to use. + + * src/cid/cidgload.c (cid_load_glyph): Update call. + * src/base/ftobjs.c, src/psaux/psobjs.c, src/type1/t1gload.c: Update + includes. + +2017-09-25 Ewald Hew + + [type1] Add Adobe engine configuration. + + Use the previously changed PS_Driver in type1 module to store + hinting engine configuration. + + * include/freetype/ftt1drv.h: New file. + Duplicate and rename config options from CFF. + * include/freetype/config/ftheader.h (FT_TYPE1_DRIVER_H): New macro. + + * src/type1/t1driver.c (t1_driver_class): Update declaration. + * src/type1/t1objs.c: Include FT_TYPE1_DRIVER_H. + (T1_Driver_Init): Update code. + +2017-09-25 Ewald Hew + + [cff] Move and rename `CFF_Driver'. + + This is so that we can use the same hinting engine parameters for + Type 1. + + * include/freetype/internal/cffotypes.h (CFF_Driver): Rename and + move to... + * include/freetype/internal/psaux.h (PS_Driver): ...here. + + * src/cff/cffdrivr.c, src/cff/cffgload.c, src/cff/cffload.c, + src/cff/cffobjs.c, src/cff/cffobjs.h, src/psaux/psft.c, + src/psaux/psobjs.c: Update references. + +2017-09-25 Ewald Hew + + [psaux, type1] Reorganize object fields. + + Make some fields more generic, so that we can access them the same + way regardless of Type 1 or CFF. + + * include/freetype/internal/psaux.h (PS_Builder): Change `TT_Face' + to `FT_Face'. + Remove unused fields. + + * src/psaux/psft.c: Update all accesses of `PS_Builder.face'. + Add some asserts to guard against casting `T1_Face' as `TT_Face'. + + * src/type1/t1objs.h (T1_GlyphSlot): Reorder fields to follow + `CFF_GlyphSlot', so that we can pretend they are the same in the + interpreter. + + * src/psaux/psobjs.c (ps_builder_init, ps_builder_add_point): + Updated with above changes. + +2017-09-25 Ewald Hew + + [psaux] Prepare for Type 1 mode. + + Add some checks for Type 1 data passing through. + + * src/psaux/psfont.h (CF2_Font): Add `isT1' flag. + * src/psaux/psfont.c (cf2_font_setup): Skip the variations and blend + code which is not applicable for Type 1. + + * src/psaux/psft.c (cf2_decoder_parse_charstrings): Avoid accessing + `decoder->cff' in Type 1 mode. + Copy `is_t1' flag to `CF2_Font'. + +2017-09-25 Ewald Hew + + [psaux, cff] Use the new objects. + + * include/freetype/internal/psaux.h, src/psaux/psauxmod.c: Fix + switching between new and old engines. + + * src/cff/cffgload.c, src/cff/cffparse.c: Update calls. + + * src/psaux/psblues.c, src/psaux/psfont.c, src/psaux/psfont.h, + src/psaux/psft.c, src/psaux/psft.h, src/psaux/psintrp.c: Update all + to use new objects. + +2017-09-24 Ewald Hew + + [psaux] Objects for new interpreter (part 2). + + Make the new objects copy over values. They are essentially wrapper + types for the different decoders/builders. + + * include/freetype/internal/psaux.h: Update declarations. + (PS_Builder): Add `is_t1' flag. + (PS_Decoder_{Get,Free}_Glyph_Callback): Renamed to... + (CFF_Decoder_{Get,Free}_Glyph_Callback: ... this. + (PS_Decoder): Updated. + Add `t1_parse_callback' member. + (PSAux_ServiceRec): Add `ps_decoder_init' member. + + * src/psaux/psdecode.h, src/psaux/psobjs.h: Update declarations. + + * src/psaux/psdecode.c, src/psaux/psobjs.c: Implement copy with two + modes. + + * src/psaux/psauxmod.c: Add builder and decoder functions to `PSAux' + service. + +2017-09-24 Ewald Hew + + [psaux] Add objects for new interpreter. + + Introduce `PS_Decoder' and `PS_Builder' which include all fields + from either Type 1 or CFF decoders/builders. + + * include/freetype/internal/psaux.h (PS_Builder, PS_Decoder): New + structs. + + * src/psaux/psobjs.c, src/psaux/psobjs.h: Add `PS_Builder' + functions. + + * src/psaux/psdecode.c, src/psaux/psdecode.h: New files to hold + `PS_Decoder' initialization functions. + + * src/psaux/psaux.c, src/psaux/Jamfile (_sources), + src/psaux/rules.mk (PSAUX_DRV_SRC): Updated. + +2017-09-24 Ewald Hew + + [psaux] Rename files. + + Replace the `cf2' file name prefix with `ps' as the Adobe engine + will be used for both PostScript Types 1 and 2 (CFF) instead of just + CFF. + + s/cf2/ps/ for all following. + + * src/psaux/cf2*: Rename files. + * src/psaux/*: Update includes. + + * src/psaux/Jamfile (_sources), src/psaux/rules.mk (PSAUX_DRC_SRC, + PSAUX_DRV_H): Update file references. + +2017-09-24 Ewald Hew + + [psaux] Minor fix. + + Use `MultiMasters' service in `psaux' instead of a call to `cff'. + The project builds if CFF_CONFIG_OPTION_OLD_ENGINE is not defined. + + * src/psaux/cf2ft.c: Update includes. + (cf2_getNormalizedVector): Use `mm->get_var_blend' instead of + `cff_get_var_blend'. + +2017-09-24 Ewald Hew + + [psaux, cff] Move `cff_random' into `psaux' service. + + NOTE: Does not compile! + + Minor fix to allow both `cff' and `psaux' to use `cff_random'. + + * src/cff/cffload.c (cff_random): Move to... + * src/psaux/psobjs.c: Here. + * src/cff/cffload.h: Move corresponding declaration to + `src/psaux/psobjs.h'. + + * include/freetype/internal/psaux.h (PSAux_ServiceRec): Register the + function here... + * src/psaux/psauxmod.c: And here. + + * src/cff/cffload.c, src/psaux/cf2intrp.c: Update code. + +2017-09-24 Ewald Hew + + [cff] Move struct declarations to `freetype/internal'. + + NOTE: Does not compile! + + This is so that the CFF functions moved to `psaux' can access the + same structs that they need. + + * src/cff/cfftypes.h: Moved to... + * include/freetype/internal/cfftypes.h: ...Here. + + * src/cff/cffobjs.h: Moved the struct declarations to... + * include/freetype/internal/cffotypes.h: ... this new file. + + * include/freetype/internal/internal.h (FT_INTERNAL_CFF_TYPES_H, + FT_INTERNAL_CFF_OBJECT_TYPES_H): New macros. + + * src/cff/cffcmap.h, src/cff/cffdrivr.c, src/cff/cffgload.c, + src/cff/cffgload.h, src/cff/cffload.h, src/cff/cffobjs.c, + src/cff/cffobjs.h, src/cff/cffparse.h, src/psaux/psobjs.h, + include/freetype/internal/psaux.h, + include/freetype/internal/services/svcfftl.h: Update includes. + + * src/cff/rules.mk (CFF_DRV_H): Updated. + +2017-09-24 Ewald Hew + + [psaux, cff] Add new service for inter-module calls. + + NOTE: Does not compile! + + This is to allow CFF functions moved to `psaux' to call functions + declared in `src/cff/cffload.h'. + + * include/freetype/internal/services/svcfftl.h: New file, setting up + a `CFFLoad' service. + + * include/freetype/internal/ftserv.h (FT_DEFINE_SERVICEDESCREC10, + FT_DEFINE_SERVICEDESCREC): New macros. + (FT_SERVICE_CFF_TABLE_LOAD_H): New macro. + + * src/cff/cffdrivr.c, src/cff/cffpic.h: Register the new service. + + * src/cff/cfftypes.h (CFF_FontRec), src/psaux/cf2font.h + (CF2_FontRec): Add service interface. + + * src/cff/cffobjs.c, src/psaux/cf2font.c, src/psaux/cf2ft.c, + src/psaux/cf2intrp.c, src/psaux/cffdecode.c: Use the new service. + +2017-09-24 Ewald Hew + + [psaux, cff] Add callbacks for inter-module calls. + + NOTE: Does not compile! + + * include/freetype/internal/psaux.h: Add function pointer + declarations. + + * src/psaux/cffdecode.c (cff_decoder_init): Update to take in + callbacks. + * src/psaux/cffdecode.h: Ditto. + + * src/cff/cffgload.c (cff_compute_max_advance, cff_slot_load): + Update calls to pass in callbacks. + * src/psaux/cf2ft.c, src/psaux/cffdecode.c: Use them. + +2017-09-24 Ewald Hew + + [psaux, cff] Create new `PSAux' service interface entries. + + NOTE: Does not compile! + + * include/freetype/internal/psaux.h: Include + FT_INTERNAL_TRUETYPE_TYPES_H. + (CFF_Builder_FuncsRec, CFF_Decocer_FuncsRec): New function tables. + (CFF_Builder): Updated. + Fix for forward declaration. + (PSAux_ServiceRec): New field `cff_decoder_funcs'. + + * src/psaux/psauxmod.c (cff_builder_funcs, cff_decoder_funcs): New + function tables. + (PSAux_Interface): Updated. + + * include/freetype/internal/tttypes.h (TT_FaceRec): Add `psaux' + service interface. + + * src/cff/cffgload.c, src/cff/cffobjs.c, src/cff/cffparse.c: Update + function calls to use psaux service. + +2017-09-24 Ewald Hew + + [psaux, cff] Move CFF builder components into `psaux' module. + + NOTE: Does not compile! + + * src/cff/cffgload.c + (cff_builder_{init,done,add_point,add_point1,add_contour,start_point,close_contour}, + cff_check_points): Move to... + * src/psaux/psobjs.c: Here. + + * src/cff/cffgload.h: Move corresponding declarations to + `src/psaux/psobjs.h'. + + * src/cff/cffgload.h (CFF_Builder): Move struct declaration to... + * include/freetype/internal/psaux.h: Here. + +2017-09-24 Ewald Hew + + [psaux, cff] Move CFF decoder components into `psaux' module. + + NOTE: Does not compile! + + * src/cff/cffgload.c (CFF_Operator, + CFF_COUNT_{CHECK_WIDTH,EXACT,CLEAR_STACK}, cff_argument_counts, + cff_operator_seac, cff_compute_bias, + cff_lookup_glyph_by_stdcharcode, + cff_decoder_{parse_charstrings,init,prepare}): Move to... + * src/psaux/cffdecode.c: This new file. + + * src/cff/cffgload.h: Move corresponding declarations to... + * src/psaux/cffdecode.h: This new file. + + * src/cff/cffgload.h (CFF_MAX_{OPERANDS,SUBRS_CALLS,TRANS_ELEMENTS}, + CFF_Decoder_Zone, CFF_Decoder): Move declarations to... + * include/freetype/internal/psaux.h: Here. + + * src/psaux/cf2ft.h: Update include. + + * src/psaux/psaux.c, src/psaux/rules.mk (PSAUX_DRV_SRC): Update with + the new file. + +2017-09-24 Ewald Hew + + [psaux, cff] Move Adobe's engine components into `psaux' module. + + This is the first patch of a sequence to move the Type 2 charstring + processing capability from the `cff' module to the `psaux' module. + + NOTE: Does not compile! + + * src/cff/cf2*: Move these files to... + * src/psaux/cf2*: Here. + + * src/cff/Jamfile (_sources), src/cff/rules.mk (CFF_DRV_SRC, + CFF_DRV_H), src/cff/cff.c, src/cff/cffgload.c: Remove file + references. + + * src/psaux/Jamfile (_sources), src/psaux/rules.mk, src/psaux/psaux.c + (PSAUX_DRV_SRC, PSAUX_DRV_H): Add file references. + +2017-09-24 Alexei Podtelezhnikov + + Tweak per-face LCD filtering controls. + + Thing are simpler with a NULL-function pointer. + + * include/freetype/internal/ftobjs.h (FT_Face_InternalRec): New + pointer to the filter function. + (FT_LibraryRec): Remove unused `lcd_filter'. + (FT_Bitmap_LcdFilterFunc, ft_lcd_filter_fir): Move from here... + * include/freetype/ftlcdfil.h (FT_Bitmap_LcdFilterFunc, + ft_lcd_filter_fir): ... to here. + + * src/base/ftobjs.c (ft_open_face_internal): NULL-initialize the + per-face filter. + (FT_Face_Properties): Set it. + * src/smooth/ftsmooth.c (ft_smooth_render_generic): Simplify. + + * src/base/ftlcdfil.c (ft_lcd_filter_fir, FT_Libary_SetLcdFilter): + Minor. + +2017-09-24 Jonathan Kew + + [sfnt] Fix `premultiply_data' (#52092). + + * src/sfnt/pngshim.c (premultiply_data): Don't use vector extension + if we have less than 16 bytes of data. + +2017-09-24 Werner Lemberg + + [otvalid] Fix handling of ValueRecords. + + For GPOS pair positioning format 1 the description of ValueRecords + in the OpenType specification (1.8.2, from today) is wrong – the + offset has to be taken from the parent structure; in this case the + `PairSet' table. + + * src/otvalid/otvgpos.c (otv_PairSet_validate): Set `extra3'. + (otv_PairPos_validate): Adjust. + +2017-09-23 Werner Lemberg + + [otvalid] Handle `GSUB' and `GPOS' v1.1 tables. + + * src/otvalid/otvgsub.c (otv_GSUB_validate), src/otvalid/otvgpos.c + (otv_GPOS_validate): Implement it. + +2017-09-23 Werner Lemberg + + [otvalid] Update common table handling to OpenType 1.8.2. + + * src/otvalid/otvcommn.c (otv_Device_validate): Handle + VariationIndex subtable. + (otv_Lookup_validate): Handle MarkFilteringSet. + +2017-09-23 Alexei Podtelezhnikov + + [build] Windows-style DLL versioning. + + * build/windows/ftver.rc: New VERSIONINFO resource. + * build/windows/vc2010/freetype.vcxproj: Further improvements. + +2017-09-23 Ben Wagner + + [truetype] Really fix #52082. + + * src/truetype/ttinterp.c (Ins_MDRP): Correct conditional. + +2017-09-23 Werner Lemberg + + [otvalid] Handle `GDEF' v1.2 and v1.3 tables. + + No validation of variation stuff yet. + + * src/otvalid/otvgdef.c (otv_MarkGlyphSets_validate): New function. + (otv_GDEF_validate): Implement it. + +2017-09-22 Werner Lemberg + + [otvalid] Handle `BASE' v1.1 table. + + No validation of variation stuff yet. + + * src/otvalid/otvbase.c (otv_BASE_validate): Implement it. + +2017-09-22 Werner Lemberg + + [otvalid] Macros for 32bit offset support. + + * src/otvalid/otvcommn.h (OTV_OPTIONAL_TABLE32, + OTV_OPTIONAL_OFFSET32, OTV_SIZE_CHECK32): New macros. + +2017-09-21 Alexei Podtelezhnikov + + [build] Simplify Visual C++ 2010 project. + + * build/windows/vc2010/freetype.vcxproj: Remove fake singlethreaded + configurations and tweak. + +2017-09-21 Werner Lemberg + + [truetype] Integer overflow (#52082). + + * src/truetype/ttinterp.c (Ins_MDRP): Avoid FT_ABS. + +2017-09-21 Werner Lemberg + + [sfnt] Fix postscript name for default instance of variation fonts. + + Problem reported by Behdad. + + * src/sfnt/sfdriver.c (sfnt_get_ps_name): Test + `is_default_instance'. + +2017-09-21 Werner Lemberg + + [truetype] Fix `mmvar' array pointers, part 2. + + The previous commit was incomplete. + + * src/truetype/ttgxvar.c: Properly initialize sub-array offsets for + `master' also. + +2017-09-21 Werner Lemberg + + [truetype] Fix `mmvar' array pointers. + + Without this change, clang's AddressSanitizer reports many runtime + errors due to misaligned addresses. + + * src/truetype/ttgxvar.c (TT_Get_MM_Var): Use multiples of pointer + size for sub-array offsets into `mmvar'. + +2017-09-20 Werner Lemberg + + [truetype] Integer overflows. + + Changes triggered by + + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3429 + + * src/truetype/ttinterp.c (Ins_SHPIX, Ins_DELTAP): Use NEG_LONG. + (Ins_MIAP): Use SUB_LONG. + +2017-09-19 Alexei Podtelezhnikov + + [build] Fix DLL builds in Visual C++ project. + + * build/windows/vc2010/freetype.vcxproj: Use DynamicLibrary in Debug + and Release configurations. + * include/freetype/config/ftconfig.h (FT_EXPORT, FT_EXPORT_DEF) + [_DLL]: Use Visual C++ extensions. + +2017-09-19 John Tytgat + + [cff] Fix family name logic of pure CFF fontdata (#52056). + + 1. If `FamilyName' is present in the CFF font, use this for + FT_Face's `family_name'. + 2. Otherwise, use the face name and chop off any subset prefix. + 3. If at this point FT_Face's `family_name' is set, use this + together with the full name to determine the style. + 4. Otherwise, use `CIDFontName' as FT_Face's `family_name'. + 5. If we don't have a valid style, use "Regular". + + Previously, FT_Face's `family_name' entry for pure CFF fontdata + nearly always was the fontname itself, instead of the `FamilyName' + entry in the CFF font (assuming there is one). + + * src/cff/cffobjs.c (cff_face_init) [pure_cff]: Implement it. + +2017-09-18 Alexei Podtelezhnikov + + [build] Declutter Visual C++ 2010-2017 project. + + * build/windows/vc2010/freetype.vcxproj: Use MaxSpeed (/02) + optimization for Release configuration throughout the project. + + +---------------------------------------------------------------------------- + +Copyright (C) 2017-2019 by +David Turner, Robert Wilhelm, and Werner Lemberg. + +This file is part of the FreeType project, and may only be used, modified, +and distributed under the terms of the FreeType project license, +LICENSE.TXT. By continuing to use, modify, or distribute this file you +indicate that you have read the license and understand and accept it +fully. + + +Local Variables: +version-control: never +coding: utf-8 +End: diff --git a/external/freetype/Jamfile b/external/freetype/Jamfile index 7e3c9822..37b4d58c 100644 --- a/external/freetype/Jamfile +++ b/external/freetype/Jamfile @@ -210,7 +210,7 @@ actions RefDoc { python -m docwriter --prefix=ft2 - --title=FreeType-2.10.0 + --title=FreeType-2.10.1 --output=$(DOC_DIR) $(FT2_INCLUDE)/freetype/*.h $(FT2_INCLUDE)/freetype/config/*.h diff --git a/external/freetype/README b/external/freetype/README index 3391a573..8f3e2bc0 100644 --- a/external/freetype/README +++ b/external/freetype/README @@ -1,4 +1,4 @@ - FreeType 2.10.0 + FreeType 2.10.1 =============== Homepage: https://www.freetype.org @@ -24,9 +24,9 @@ and download one of the following files. - freetype-doc-2.10.0.tar.bz2 - freetype-doc-2.10.0.tar.gz - ftdoc2100.zip + freetype-doc-2.10.1.tar.xz + freetype-doc-2.10.1.tar.gz + ftdoc2101.zip To view the documentation online, go to diff --git a/external/freetype/builds/toplevel.mk b/external/freetype/builds/toplevel.mk index 24fa7fad..333b775c 100644 --- a/external/freetype/builds/toplevel.mk +++ b/external/freetype/builds/toplevel.mk @@ -208,7 +208,7 @@ patch := $(firstword $(patch)) dist: -rm -rf tmp rm -f freetype-$(version).tar.gz - rm -f freetype-$(version).tar.bz2 + rm -f freetype-$(version).tar.xz rm -f ft$(winversion).zip for d in `find . -wholename '*/.git' -prune \ @@ -235,7 +235,7 @@ dist: tar -H ustar -chf - freetype-$(version) \ | gzip -9 -c > freetype-$(version).tar.gz tar -H ustar -chf - freetype-$(version) \ - | bzip2 -c > freetype-$(version).tar.bz2 + | xz -c > freetype-$(version).tar.xz @# Use CR/LF for zip files. zip -lr9 ft$(winversion).zip freetype-$(version) diff --git a/external/freetype/builds/unix/aclocal.m4 b/external/freetype/builds/unix/aclocal.m4 index eb7517a9..12b4b994 100644 --- a/external/freetype/builds/unix/aclocal.m4 +++ b/external/freetype/builds/unix/aclocal.m4 @@ -1,6 +1,6 @@ -# generated automatically by aclocal 1.15 -*- Autoconf -*- +# generated automatically by aclocal 1.15.1 -*- Autoconf -*- -# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -736,7 +736,6 @@ _LT_CONFIG_SAVE_COMMANDS([ cat <<_LT_EOF >> "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION -# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. diff --git a/external/freetype/builds/unix/config.guess b/external/freetype/builds/unix/config.guess index a81aa505..41b8b854 100755 --- a/external/freetype/builds/unix/config.guess +++ b/external/freetype/builds/unix/config.guess @@ -2,7 +2,7 @@ # Attempt to guess a canonical system name. # Copyright 1992-2019 Free Software Foundation, Inc. -timestamp='2019-01-15' +timestamp='2019-06-10' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -262,6 +262,9 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in *:SolidBSD:*:*) echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE" exit ;; + *:OS108:*:*) + echo "$UNAME_MACHINE"-unknown-os108_"$UNAME_RELEASE" + exit ;; macppc:MirBSD:*:*) echo powerpc-unknown-mirbsd"$UNAME_RELEASE" exit ;; @@ -985,22 +988,50 @@ EOF exit ;; mips:Linux:*:* | mips64:Linux:*:*) set_cc_for_build + IS_GLIBC=0 + test x"${LIBC}" = xgnu && IS_GLIBC=1 sed 's/^ //' << EOF > "$dummy.c" #undef CPU - #undef ${UNAME_MACHINE} - #undef ${UNAME_MACHINE}el + #undef mips + #undef mipsel + #undef mips64 + #undef mips64el + #if ${IS_GLIBC} && defined(_ABI64) + LIBCABI=gnuabi64 + #else + #if ${IS_GLIBC} && defined(_ABIN32) + LIBCABI=gnuabin32 + #else + LIBCABI=${LIBC} + #endif + #endif + + #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa64r6 + #else + #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa32r6 + #else + #if defined(__mips64) + CPU=mips64 + #else + CPU=mips + #endif + #endif + #endif + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=${UNAME_MACHINE}el + MIPS_ENDIAN=el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=${UNAME_MACHINE} + MIPS_ENDIAN= #else - CPU= + MIPS_ENDIAN= #endif #endif EOF - eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU'`" - test "x$CPU" != x && { echo "$CPU-unknown-linux-$LIBC"; exit; } + eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'`" + test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } ;; mips64el:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" @@ -1113,7 +1144,7 @@ EOF *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac - echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}{$UNAME_VERSION}" + echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}" exit ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then @@ -1297,38 +1328,39 @@ EOF echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE" exit ;; *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - set_cc_for_build - if test "$UNAME_PROCESSOR" = unknown ; then - UNAME_PROCESSOR=powerpc + UNAME_PROCESSOR=`uname -p` + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + if command -v xcode-select > /dev/null 2> /dev/null && \ + ! xcode-select --print-path > /dev/null 2> /dev/null ; then + # Avoid executing cc if there is no toolchain installed as + # cc will be a stub that puts up a graphical alert + # prompting the user to install developer tools. + CC_FOR_BUILD=no_compiler_found + else + set_cc_for_build fi - if test "`echo "$UNAME_RELEASE" | sed -e 's/\..*//'`" -le 10 ; then - if [ "$CC_FOR_BUILD" != no_compiler_found ]; then - if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - case $UNAME_PROCESSOR in - i386) UNAME_PROCESSOR=x86_64 ;; - powerpc) UNAME_PROCESSOR=powerpc64 ;; - esac - fi - # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc - if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_PPC >/dev/null - then - UNAME_PROCESSOR=powerpc - fi + if [ "$CC_FOR_BUILD" != no_compiler_found ]; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + case $UNAME_PROCESSOR in + i386) UNAME_PROCESSOR=x86_64 ;; + powerpc) UNAME_PROCESSOR=powerpc64 ;; + esac + fi + # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc + if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_PPC >/dev/null + then + UNAME_PROCESSOR=powerpc fi elif test "$UNAME_PROCESSOR" = i386 ; then - # Avoid executing cc on OS X 10.9, as it ships with a stub - # that puts up a graphical alert prompting to install - # developer tools. Any system running Mac OS X 10.7 or - # later (Darwin 11 and later) is required to have a 64-bit - # processor. This is not true of the ARM version of Darwin - # that Apple uses in portable devices. - UNAME_PROCESSOR=x86_64 + # uname -m returns i386 or x86_64 + UNAME_PROCESSOR=$UNAME_MACHINE fi echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE" exit ;; @@ -1433,6 +1465,143 @@ EOF exit ;; esac +# No uname command or uname output not recognized. +set_cc_for_build +cat > "$dummy.c" < +#include +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#include +#if defined(_SIZE_T_) || defined(SIGLOST) +#include +#endif +#endif +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); +#endif + +#if defined (vax) +#if !defined (ultrix) +#include +#if defined (BSD) +#if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +#else +#if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#endif +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#else +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname un; + uname (&un); + printf ("vax-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("vax-dec-ultrix\n"); exit (0); +#endif +#endif +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname *un; + uname (&un); + printf ("mips-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("mips-dec-ultrix\n"); exit (0); +#endif +#endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. +test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } + echo "$0: unable to guess system type" >&2 case "$UNAME_MACHINE:$UNAME_SYSTEM" in diff --git a/external/freetype/builds/unix/config.sub b/external/freetype/builds/unix/config.sub index 3b4c7624..5b158ac4 100755 --- a/external/freetype/builds/unix/config.sub +++ b/external/freetype/builds/unix/config.sub @@ -2,7 +2,7 @@ # Configuration validation subroutine script. # Copyright 1992-2019 Free Software Foundation, Inc. -timestamp='2019-01-05' +timestamp='2019-05-23' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -822,7 +822,9 @@ case $basic_machine in cpu=m68k vendor=next case $os in - nextstep* ) + openstep*) + ;; + nextstep*) ;; ns2*) os=nextstep2 @@ -1170,7 +1172,7 @@ case $cpu-$vendor in | asmjs \ | ba \ | be32 | be64 \ - | bfin | bs2000 \ + | bfin | bpf | bs2000 \ | c[123]* | c30 | [cjt]90 | c4x \ | c8051 | clipper | craynv | csky | cydra \ | d10v | d30v | dlx | dsp16xx \ @@ -1245,7 +1247,8 @@ case $cpu-$vendor in | v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \ | vax \ | visium \ - | w65 | wasm32 \ + | w65 \ + | wasm32 | wasm64 \ | we32k \ | x86 | x86_64 | xc16x | xgate | xps100 \ | xstormy16 | xtensa* \ @@ -1365,7 +1368,7 @@ case $os in | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ | skyos* | haiku* | rdos* | toppers* | drops* | es* \ | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ - | midnightbsd* | amdhsa* | unleashed* | emscripten*) + | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi*) # Remember, each alternative MUST END IN *, to match a version number. ;; qnx*) diff --git a/external/freetype/builds/unix/configure b/external/freetype/builds/unix/configure index 5917c6e4..f6b65306 100755 --- a/external/freetype/builds/unix/configure +++ b/external/freetype/builds/unix/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for FreeType 2.10. +# Generated by GNU Autoconf 2.69 for FreeType 2.10.1. # # Report bugs to . # @@ -590,8 +590,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='FreeType' PACKAGE_TARNAME='freetype' -PACKAGE_VERSION='2.10' -PACKAGE_STRING='FreeType 2.10' +PACKAGE_VERSION='2.10.1' +PACKAGE_STRING='FreeType 2.10.1' PACKAGE_BUGREPORT='freetype@nongnu.org' PACKAGE_URL='' @@ -1335,7 +1335,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures FreeType 2.10 to adapt to many kinds of systems. +\`configure' configures FreeType 2.10.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1400,7 +1400,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of FreeType 2.10:";; + short | recursive ) echo "Configuration of FreeType 2.10.1:";; esac cat <<\_ACEOF @@ -1549,7 +1549,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -FreeType configure 2.10 +FreeType configure 2.10.1 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2147,7 +2147,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by FreeType $as_me 2.10, which was +It was created by FreeType $as_me 2.10.1, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2503,7 +2503,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu # Don't forget to update `docs/VERSIONS.TXT'! -version_info='23:0:17' +version_info='23:1:17' ft_version=`echo $version_info | tr : .` @@ -15478,7 +15478,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by FreeType $as_me 2.10, which was +This file was extended by FreeType $as_me 2.10.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -15544,7 +15544,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -FreeType config.status 2.10 +FreeType config.status 2.10.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -16613,7 +16613,6 @@ $as_echo "$as_me: executing $ac_file commands" >&6;} cat <<_LT_EOF >> "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION -# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. diff --git a/external/freetype/builds/unix/configure.ac b/external/freetype/builds/unix/configure.ac index ad3c694f..d374088a 100644 --- a/external/freetype/builds/unix/configure.ac +++ b/external/freetype/builds/unix/configure.ac @@ -11,13 +11,13 @@ # indicate that you have read the license and understand and accept it # fully. -AC_INIT([FreeType], [2.10], [freetype@nongnu.org], [freetype]) +AC_INIT([FreeType], [2.10.1], [freetype@nongnu.org], [freetype]) AC_CONFIG_SRCDIR([ftconfig.in]) # Don't forget to update `docs/VERSIONS.TXT'! -version_info='23:0:17' +version_info='23:1:17' AC_SUBST([version_info]) ft_version=`echo $version_info | tr : .` AC_SUBST([ft_version]) diff --git a/external/freetype/builds/unix/configure.raw b/external/freetype/builds/unix/configure.raw index acefa119..a1a6dbeb 100644 --- a/external/freetype/builds/unix/configure.raw +++ b/external/freetype/builds/unix/configure.raw @@ -17,7 +17,7 @@ AC_CONFIG_SRCDIR([ftconfig.in]) # Don't forget to update `docs/VERSIONS.TXT'! -version_info='23:0:17' +version_info='23:1:17' AC_SUBST([version_info]) ft_version=`echo $version_info | tr : .` AC_SUBST([ft_version]) diff --git a/external/freetype/builds/unix/ltmain.sh b/external/freetype/builds/unix/ltmain.sh old mode 100644 new mode 100755 diff --git a/external/freetype/builds/vms/LIBS.OPT_IA64 b/external/freetype/builds/vms/LIBS.OPT_IA64 new file mode 100644 index 0000000000000000000000000000000000000000..6768c7662d422b504582fa9e9e1d11a71a455628 GIT binary patch literal 82 ucmb1QD6TA4$;nJAN-V0h0@4L}>3aD&N%}yh6uMkel@Ux%0$r{OCIbMmQyoYE literal 0 HcmV?d00001 diff --git a/external/freetype/builds/vms/_LINK.OPT_IA64 b/external/freetype/builds/vms/_LINK.OPT_IA64 new file mode 100644 index 0000000000000000000000000000000000000000..b8cbd1bc781cf7afcef6d2e2db4c403fcdecd480 GIT binary patch literal 14464 zcmb7L+j84D66H7S7wpvDCVQD3XR@=iTa^b}vJ%(Iwn|cxnSDXQ6eP1k5ei7za=v~V zAZay#1IqKJhtthQ-@5_*F3V-DM6Ig2Xo?5*_Ls}WKeON0Pun|PiU*Z9+PwXCvK)!g zwcL$ley_w->(Be$+u8hfbUFSozkHSb{RG90dSvkLA^K`7H!AUgA74hX$YrSv`_ey7 z(fNX9e}njIS&?W)jCG|L^XzO8-D+tf^WRLfD870$e;xdee}o?fv2(T656a4PHRdP5 z_Uq3*SG8&w{1yDhjb177p)zXCpc(e1#YNF1Or8A;at|pYQzv}zNayPbSz4Uu6aunQ zBD4Uqv^Za_#8|E6zHG#`UhPX&^OJuI&f#cUEQ4ZXwJDVt7i+H0KR}+1tX?yA8M2Q! zZyE|-F)2#Vx3C^s?4mJBZaHV2hLRQUHwNl(@|3&t&N)GAjE=@2Uy*Wi&->$pQGO9sIJNQDC zu4;4F8T?vDM<29jWnY6nJ}I>}zQ;kUkm@MgJ;=(hf6&?t%cVwrf>o`!7*B+imCBOv z3fXr^t3Acc=p7{}?oTk2SiFn*i8fowT{U~1;_vWNS#9>zDflwMXmH=46Nu2KP`z|# zw&%5JHY9*`&rwVYQ`1RaU{fp2J6ZFV4n~i|1;L*FzDo<@Ms9f;N&3qFl&Okp!`v@} z8OO?SeJ#jo88nS_b(tZP7Hq3Bskc#P?Kf>nuezqvUx;g26Ak-D(&APZkpW>Awx_&N zhsbf97NQkL&#Su)Se6=iYb*(+&*#hMNfa!#J$8BMLwzVh-$(jy$rQr>w@SuzJK z_IGVi1xkfow$sqk$o#Vac7~P2+F@z-uJnt`YEw|t5VQeF**+E3DHZRVM3%is3V{2ORy5KdJcesr($&of!7=QRHf}~2n)ik{|2Q;_Rr)g* zJgpniVlTAugDUM6VyWXpCaQ*$hB8D|uc^~vO2PJhFKe5nk7b?51I(dURndqEm?fa4 zx^`bIR5Q(2G^qMj^*<<95zQx6Z0`Lyhx+PiKPpof+M5_*=Q}N^o$?b8Jhj73ib|Hj z9tZYRJ(>p#p5Ptws;d1V8&|p(OA4eM#0(3&FNbY6Lkyb1$<<*$@J12OSvKv4ttam1 z9Mbs|`#83j|+ zww=XBD*)(4M`S2+mONYF6EKc%cdCjwLM`0xo6>exuD4(Y!;$=q_Nx)Bjy-m)a=qQ@ znuq={_n_;5T}sa#)N0rb^?0g|l(mYLipp39yHG|)KOy0ue6|{2_|+IzSoWQ`WS;y& zQ14G^K-`)_RgG+dN&_=;FB$nN_Yc^C^w>7dF*x-8Bbri|?;nF61-pdP6s2E&;BH^c zWuB|LcJsw3)ZEc;!rdp0o+zS<7qjOMIDURJAEdfX{>(p(;PenuPAPm7L5H#qO~I;Aw&61a;H zFMd+K>dr!RF~#6nrZh-4*=mwxDf3y2k{x#noFe)1`OqinDV^F;&&Z3n?5U9on%D_NB0Y z?C^6y1RpijrVVao$o8! zoiLX1WF^;IK{qL-?}Stk(ZL@Ux$r(-mTVRMHjKe zli}iCGGDJnZeJzPh^%QW*|czBRNk@%Hwn))drG4A&7k|jktCMJQpD24-mz}PUHcYo zvg6zEi|IUqU*8YkLzW%Tnjv zIhaK8jPFscsV$F*K!)?EYMPN+jj=Dqdw)w~Zt64Z^!cTZlWNlHstUjZ;yx+Jq92cyLFPfZ&Alk|75os4$s^4JBmxt} z@k{79&=M46)k+$Yi-lx-LuxrcRn0xEfW9hv&2O55p2(BGNAGyzewSz;=n8Ws=^p?> z8AJaA7<}>X;e&vNx%$Z6>^$+aE*N$#OpdZOD*>Ypq*IfyV{CK1ut#^!0phku4wmE18|%} zYx__NaE&e5oQb=AK`*quZY96W@#$UYzMGE{08is2%9`vBtjAyF-;fCwUrsD%fbrIFP}FTlppFj - + @@ -41,7 +41,7 @@ - + @@ -61,7 +61,7 @@ - + @@ -81,7 +81,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -121,7 +121,7 @@ - + @@ -141,7 +141,7 @@ - + @@ -161,7 +161,7 @@ - + @@ -181,7 +181,7 @@ - + @@ -201,7 +201,7 @@ - + @@ -221,7 +221,7 @@ - + @@ -241,7 +241,7 @@ - + @@ -261,7 +261,7 @@ - + @@ -281,7 +281,7 @@ - + @@ -301,7 +301,7 @@ - + @@ -321,7 +321,7 @@ - + @@ -341,7 +341,7 @@ - + @@ -361,7 +361,7 @@ - + @@ -381,7 +381,7 @@ - + @@ -401,7 +401,7 @@ - + @@ -421,7 +421,7 @@ - + @@ -441,7 +441,7 @@ - + @@ -461,7 +461,7 @@ - + @@ -481,7 +481,7 @@ - + @@ -501,7 +501,7 @@ - + @@ -521,7 +521,7 @@ - + @@ -541,7 +541,7 @@ - + @@ -561,7 +561,7 @@ - + @@ -581,7 +581,7 @@ - + @@ -601,7 +601,7 @@ - + @@ -621,7 +621,7 @@ - + @@ -641,7 +641,7 @@ - + @@ -661,7 +661,7 @@ - + @@ -681,7 +681,7 @@ - + @@ -701,7 +701,7 @@ - + @@ -721,7 +721,7 @@ - + @@ -741,7 +741,7 @@ - + @@ -758,7 +758,7 @@ - + diff --git a/external/freetype/builds/wince/vc2005-ce/index.html b/external/freetype/builds/wince/vc2005-ce/index.html index 76f56cf4..16a10625 100644 --- a/external/freetype/builds/wince/vc2005-ce/index.html +++ b/external/freetype/builds/wince/vc2005-ce/index.html @@ -21,14 +21,14 @@ the following targets:
  • PPC/SP WM6 (Windows Mobile 6)
  • -It compiles the following libraries from the FreeType 2.10.0 sources:

    +It compiles the following libraries from the FreeType 2.10.1 sources:

      -    freetype2100.lib     - release build; single threaded
      -    freetype2100_D.lib   - debug build;   single threaded
      -    freetype2100MT.lib   - release build; multi-threaded
      -    freetype2100MT_D.lib - debug build;   multi-threaded
      + freetype2101.lib - release build; single threaded + freetype2101_D.lib - debug build; single threaded + freetype2101MT.lib - release build; multi-threaded + freetype2101MT_D.lib - debug build; multi-threaded

    Be sure to extract the files with the Windows (CR+LF) line endings. ZIP diff --git a/external/freetype/builds/wince/vc2008-ce/freetype.vcproj b/external/freetype/builds/wince/vc2008-ce/freetype.vcproj index a0ec3185..f9479dae 100644 --- a/external/freetype/builds/wince/vc2008-ce/freetype.vcproj +++ b/external/freetype/builds/wince/vc2008-ce/freetype.vcproj @@ -88,7 +88,7 @@ /> PPC/SP WM6 (Windows Mobile 6) -It compiles the following libraries from the FreeType 2.10.0 sources:

    +It compiles the following libraries from the FreeType 2.10.1 sources:

      -    freetype2100.lib     - release build; single threaded
      -    freetype2100_D.lib   - debug build;   single threaded
      -    freetype2100MT.lib   - release build; multi-threaded
      -    freetype2100MT_D.lib - debug build;   multi-threaded
      + freetype2101.lib - release build; single threaded + freetype2101_D.lib - debug build; single threaded + freetype2101MT.lib - release build; multi-threaded + freetype2101MT_D.lib - debug build; multi-threaded

    Be sure to extract the files with the Windows (CR+LF) line endings. ZIP diff --git a/external/freetype/builds/windows/vc2010/index.html b/external/freetype/builds/windows/vc2010/index.html index 0fe294d6..eed4dd33 100644 --- a/external/freetype/builds/windows/vc2010/index.html +++ b/external/freetype/builds/windows/vc2010/index.html @@ -12,7 +12,7 @@

    This directory contains solution and project files for Visual C++ 2010 or newer, named freetype.sln, and freetype.vcxproj. It compiles the following libraries -from the FreeType 2.10.0 sources:

    +from the FreeType 2.10.1 sources:

    • freetype.dll using 'Release' or 'Debug' configurations
    • diff --git a/external/freetype/builds/windows/visualc/freetype.vcproj b/external/freetype/builds/windows/visualc/freetype.vcproj index 385c93ea..ecb5b055 100644 --- a/external/freetype/builds/windows/visualc/freetype.vcproj +++ b/external/freetype/builds/windows/visualc/freetype.vcproj @@ -185,7 +185,6 @@ This directory contains project files freetype.dsp for Visual C++ 6.0, and freetype.vcproj for Visual C++ 2002 through 2008, which you might need to upgrade automatically. -It compiles the following libraries from the FreeType 2.10.0 sources:

      +It compiles the following libraries from the FreeType 2.10.1 sources:

      • freetype.dll using 'Release' or 'Debug' configurations
      • diff --git a/external/freetype/builds/windows/visualce/freetype.dsp b/external/freetype/builds/windows/visualce/freetype.dsp index 2ac17d6b..cb1205d7 100644 --- a/external/freetype/builds/windows/visualce/freetype.dsp +++ b/external/freetype/builds/windows/visualce/freetype.dsp @@ -54,7 +54,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"..\..\..\objs\freetype2100.lib" +# ADD LIB32 /nologo /out:"..\..\..\objs\freetype2101.lib" !ELSEIF "$(CFG)" == "freetype - Win32 Debug" @@ -78,7 +78,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"..\..\..\objs\freetype2100_D.lib" +# ADD LIB32 /nologo /out:"..\..\..\objs\freetype2101_D.lib" !ELSEIF "$(CFG)" == "freetype - Win32 Debug Multithreaded" @@ -102,8 +102,8 @@ BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib -# ADD BASE LIB32 /nologo /out:"lib\freetype2100_D.lib" -# ADD LIB32 /nologo /out:"..\..\..\objs\freetype2100MT_D.lib" +# ADD BASE LIB32 /nologo /out:"lib\freetype2101_D.lib" +# ADD LIB32 /nologo /out:"..\..\..\objs\freetype2101MT_D.lib" !ELSEIF "$(CFG)" == "freetype - Win32 Release Multithreaded" @@ -126,8 +126,8 @@ BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib -# ADD BASE LIB32 /nologo /out:"lib\freetype2100.lib" -# ADD LIB32 /nologo /out:"..\..\..\objs\freetype2100MT.lib" +# ADD BASE LIB32 /nologo /out:"lib\freetype2101.lib" +# ADD LIB32 /nologo /out:"..\..\..\objs\freetype2101MT.lib" !ELSEIF "$(CFG)" == "freetype - Win32 Release Singlethreaded" @@ -151,8 +151,8 @@ BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib -# ADD BASE LIB32 /nologo /out:"..\..\..\objs\freetype2100.lib" -# ADD LIB32 /out:"..\..\..\objs\freetype2100ST.lib" +# ADD BASE LIB32 /nologo /out:"..\..\..\objs\freetype2101.lib" +# ADD LIB32 /out:"..\..\..\objs\freetype2101ST.lib" # SUBTRACT LIB32 /nologo !ELSEIF "$(CFG)" == "freetype - Win32 Debug Singlethreaded" @@ -177,8 +177,8 @@ BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib -# ADD BASE LIB32 /nologo /out:"..\..\..\objs\freetype2100_D.lib" -# ADD LIB32 /nologo /out:"..\..\..\objs\freetype2100ST_D.lib" +# ADD BASE LIB32 /nologo /out:"..\..\..\objs\freetype2101_D.lib" +# ADD LIB32 /nologo /out:"..\..\..\objs\freetype2101ST_D.lib" !ENDIF diff --git a/external/freetype/builds/windows/visualce/freetype.vcproj b/external/freetype/builds/windows/visualce/freetype.vcproj index d1ae64b1..96b51e90 100644 --- a/external/freetype/builds/windows/visualce/freetype.vcproj +++ b/external/freetype/builds/windows/visualce/freetype.vcproj @@ -87,7 +87,7 @@ /> PPC/SP WM6 (Windows Mobile 6)
      -It compiles the following libraries from the FreeType 2.10.0 sources:

      +It compiles the following libraries from the FreeType 2.10.1 sources:

        -    freetype2100.lib     - release build; single threaded
        -    freetype2100_D.lib   - debug build;   single threaded
        -    freetype2100MT.lib   - release build; multi-threaded
        -    freetype2100MT_D.lib - debug build;   multi-threaded
        + freetype2101.lib - release build; single threaded + freetype2101_D.lib - debug build; single threaded + freetype2101MT.lib - release build; multi-threaded + freetype2101MT_D.lib - debug build; multi-threaded

      Be sure to extract the files with the Windows (CR+LF) line endings. ZIP diff --git a/external/freetype/docs/CHANGES b/external/freetype/docs/CHANGES index 5965a576..f36cb19b 100644 --- a/external/freetype/docs/CHANGES +++ b/external/freetype/docs/CHANGES @@ -1,5 +1,59 @@ -CHANGES BETWEEN 2.9.1 and 2.10 +CHANGES BETWEEN 2.10.0 and 2.10.1 + + I. IMPORTANT BUG FIXES + + - The bytecode hinting of OpenType variation fonts was flawed, since + the data in the `CVAR' table wasn't correctly applied. + + + II. MISCELLANEOUS + + - Auto-hinter support for Mongolian. + + - For distribution, `.tar.bz2' packages are replaced with `.tar.xz' + bundles. + + - The handling of the default character in PCF fonts as introduced + in version 2.10.0 was partially broken, causing premature abortion + of charmap iteration for many fonts. + + - If `FT_Set_Named_Instance' was called with the same arguments + twice in a row, the function returned an incorrect error code the + second time. + + - Direct rendering using FT_RASTER_FLAG_DIRECT crashed (bug + introduced in version 2.10.0). + + - Increased precision while computing OpenType font variation + instances. + + - The flattening algorithm of cubic Bezier curves was slightly + changed to make it faster. This can cause very subtle rendering + changes, which aren't noticeable by the eye, however. + + - The auto-hinter now disables hinting if there are blue zones + defined for a `style' (i.e., a certain combination of a script and + its related typographic features) but the font doesn't contain any + characters needed to set up at least one blue zone. + + - The `ftmulti' demo program now supports multiple hidden axes with + the same name tag. + + - `ftview', `ftstring', and `ftgrid' got a `-k' command line option + to emulate a sequence of keystrokes at start-up. + + - `ftview', `ftstring', and `ftgrid' now support screen dumping to a + PNG file. + + - The bytecode debugger, `ttdebug', now supports variation TrueType + fonts; a variation font instance can be selected with the new `-d' + command line option. + + +====================================================================== + +CHANGES BETWEEN 2.9.1 and 2.10.0 I. IMPORTANT CHANGES diff --git a/external/freetype/docs/VERSIONS.TXT b/external/freetype/docs/VERSIONS.TXT index e8154bc5..5cdf3785 100644 --- a/external/freetype/docs/VERSIONS.TXT +++ b/external/freetype/docs/VERSIONS.TXT @@ -52,6 +52,7 @@ on _most_ systems, but not all of them: release libtool so ------------------------------- + 2.10.1 23.1.17 6.17.1 2.10.0 23.0.17 6.17.0 2.9.1 22.1.16 6.16.1 2.9.0 22.0.16 6.16.0 diff --git a/external/freetype/docs/freetype-config.1 b/external/freetype/docs/freetype-config.1 index 98d1ca11..96ff0f28 100644 --- a/external/freetype/docs/freetype-config.1 +++ b/external/freetype/docs/freetype-config.1 @@ -1,4 +1,4 @@ -.TH FREETYPE-CONFIG 1 "March 2019" "FreeType 2.10.0" +.TH FREETYPE-CONFIG 1 "July 2019" "FreeType 2.10.1" . . .SH NAME diff --git a/external/freetype/docs/reference/site/404.html b/external/freetype/docs/reference/site/404.html index 4322e97f..4f0f50e9 100644 --- a/external/freetype/docs/reference/site/404.html +++ b/external/freetype/docs/reference/site/404.html @@ -10,7 +10,7 @@ - + @@ -40,7 +40,7 @@ - FreeType-2.10.0 API Reference + FreeType-2.10.1 API Reference @@ -94,7 +94,7 @@