Merge branch 'main' into audio-engine

This commit is contained in:
Alexander Batalov 2022-07-12 10:13:51 +03:00
commit e691b3968c
3 changed files with 90 additions and 23 deletions

View File

@ -356,8 +356,10 @@ int gKeyboardLayout;
unsigned char gPressedPhysicalKeysCount;
SDL_Window* gSdlWindow = NULL;
SDL_Surface* gSdlWindowSurface = NULL;
SDL_Surface* gSdlSurface = NULL;
SDL_Renderer* gSdlRenderer = NULL;
SDL_Texture* gSdlTexture = NULL;
SDL_Surface* gSdlTextureSurface = NULL;
// 0x4C8A70
int coreInit(int a1)
@ -1268,7 +1270,6 @@ void _GNW95_process_message()
case SDL_WINDOWEVENT_SIZE_CHANGED:
// TODO: Recreate gSdlSurface in case size really changed (i.e.
// not alt-tabbing in fullscreen mode).
gSdlWindowSurface = SDL_GetWindowSurface(gSdlWindow);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
gProgramIsActive = true;
@ -2014,24 +2015,67 @@ int _init_vesa_mode(int width, int height)
int _GNW95_init_window(int width, int height, bool fullscreen)
{
if (gSdlWindow == NULL) {
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
return -1;
}
gSdlWindow = SDL_CreateWindow(gProgramWindowTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
Uint32 windowFlags = SDL_WINDOW_OPENGL;
if (fullscreen) {
windowFlags |= SDL_WINDOW_FULLSCREEN;
}
gSdlWindow = SDL_CreateWindow(gProgramWindowTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, windowFlags);
if (gSdlWindow == NULL) {
return -1;
}
gSdlWindowSurface = SDL_GetWindowSurface(gSdlWindow);
if (gSdlWindowSurface == NULL) {
SDL_DestroyWindow(gSdlWindow);
gSdlWindow = NULL;
return -1;
gSdlRenderer = SDL_CreateRenderer(gSdlWindow, -1, 0);
if (gSdlRenderer == NULL) {
goto err;
}
if (SDL_RenderSetLogicalSize(gSdlRenderer, width, height) != 0) {
goto err;
}
gSdlTexture = SDL_CreateTexture(gSdlRenderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, width, height);
if (gSdlTexture == NULL) {
goto err;
}
Uint32 format;
if (SDL_QueryTexture(gSdlTexture, &format, NULL, NULL, NULL) != 0) {
goto err;
}
gSdlTextureSurface = SDL_CreateRGBSurfaceWithFormat(0, width, height, SDL_BITSPERPIXEL(format), format);
if (gSdlTextureSurface == NULL) {
goto err;
}
}
return 0;
err:
if (gSdlTexture != NULL) {
SDL_DestroyTexture(gSdlTexture);
gSdlTexture = NULL;
}
if (gSdlRenderer != NULL) {
SDL_DestroyRenderer(gSdlRenderer);
gSdlRenderer = NULL;
}
if (gSdlWindow != NULL) {
SDL_DestroyWindow(gSdlWindow);
gSdlWindow = NULL;
}
return -1;
}
// calculate shift for mask
@ -2133,8 +2177,11 @@ void directDrawSetPaletteInRange(unsigned char* palette, int start, int count)
}
SDL_SetPaletteColors(gSdlSurface->format->palette, colors, start, count);
SDL_BlitSurface(gSdlSurface, NULL, gSdlWindowSurface, NULL);
SDL_UpdateWindowSurface(gSdlWindow);
SDL_BlitSurface(gSdlSurface, NULL, gSdlTextureSurface, NULL);
SDL_UpdateTexture(gSdlTexture, NULL, gSdlTextureSurface->pixels, gSdlTextureSurface->pitch);
SDL_RenderClear(gSdlRenderer);
SDL_RenderCopy(gSdlRenderer, gSdlTexture, NULL, NULL);
SDL_RenderPresent(gSdlRenderer);
} else {
for (int index = start; index < start + count; index++) {
unsigned short r = palette[0] << 2;
@ -2177,8 +2224,11 @@ void directDrawSetPalette(unsigned char* palette)
}
SDL_SetPaletteColors(gSdlSurface->format->palette, colors, 0, 256);
SDL_BlitSurface(gSdlSurface, NULL, gSdlWindowSurface, NULL);
SDL_UpdateWindowSurface(gSdlWindow);
SDL_BlitSurface(gSdlSurface, NULL, gSdlTextureSurface, NULL);
SDL_UpdateTexture(gSdlTexture, NULL, gSdlTextureSurface->pixels, gSdlTextureSurface->pitch);
SDL_RenderClear(gSdlRenderer);
SDL_RenderCopy(gSdlRenderer, gSdlTexture, NULL, NULL);
SDL_RenderPresent(gSdlRenderer);
} else {
for (int index = 0; index < 256; index++) {
unsigned short r = palette[index * 3] << 2;
@ -2258,8 +2308,11 @@ void _GNW95_ShowRect(unsigned char* src, int srcPitch, int a3, int srcX, int src
SDL_Rect destRect;
destRect.x = destX;
destRect.y = destY;
SDL_BlitSurface(gSdlSurface, &srcRect, gSdlWindowSurface, &destRect);
SDL_UpdateWindowSurface(gSdlWindow);
SDL_BlitSurface(gSdlSurface, &srcRect, gSdlTextureSurface, &destRect);
SDL_UpdateTexture(gSdlTexture, NULL, gSdlTextureSurface->pixels, gSdlTextureSurface->pitch);
SDL_RenderClear(gSdlRenderer);
SDL_RenderCopy(gSdlRenderer, gSdlTexture, NULL, NULL);
SDL_RenderPresent(gSdlRenderer);
}
// 0x4CB93C
@ -2298,8 +2351,11 @@ void _GNW95_MouseShowRect16(unsigned char* src, int srcPitch, int a3, int srcX,
SDL_Rect destRect;
destRect.x = destX;
destRect.y = destY;
SDL_BlitSurface(gSdlSurface, &srcRect, gSdlWindowSurface, &destRect);
SDL_UpdateWindowSurface(gSdlWindow);
SDL_BlitSurface(gSdlSurface, &srcRect, gSdlTextureSurface, &destRect);
SDL_UpdateTexture(gSdlTexture, NULL, gSdlTextureSurface->pixels, gSdlTextureSurface->pitch);
SDL_RenderClear(gSdlRenderer);
SDL_RenderCopy(gSdlRenderer, gSdlTexture, NULL, NULL);
SDL_RenderPresent(gSdlRenderer);
}
// 0x4CBA44
@ -2346,8 +2402,11 @@ void _GNW95_MouseShowTransRect16(unsigned char* src, int srcPitch, int a3, int s
SDL_Rect destRect;
destRect.x = destX;
destRect.y = destY;
SDL_BlitSurface(gSdlSurface, &srcRect, gSdlWindowSurface, &destRect);
SDL_UpdateWindowSurface(gSdlWindow);
SDL_BlitSurface(gSdlSurface, &srcRect, gSdlTextureSurface, &destRect);
SDL_UpdateTexture(gSdlTexture, NULL, gSdlTextureSurface->pixels, gSdlTextureSurface->pitch);
SDL_RenderClear(gSdlRenderer);
SDL_RenderCopy(gSdlRenderer, gSdlTexture, NULL, NULL);
SDL_RenderPresent(gSdlRenderer);
}
// Clears drawing surface.
@ -2369,8 +2428,11 @@ void _GNW95_zero_vid_mem()
SDL_UnlockSurface(gSdlSurface);
SDL_BlitSurface(gSdlSurface, NULL, gSdlWindowSurface, NULL);
SDL_UpdateWindowSurface(gSdlWindow);
SDL_BlitSurface(gSdlSurface, NULL, gSdlTextureSurface, NULL);
SDL_UpdateTexture(gSdlTexture, NULL, gSdlTextureSurface->pixels, gSdlTextureSurface->pitch);
SDL_RenderClear(gSdlRenderer);
SDL_RenderCopy(gSdlRenderer, gSdlTexture, NULL, NULL);
SDL_RenderPresent(gSdlRenderer);
}
// 0x4CBC90

View File

@ -522,8 +522,10 @@ extern int gKeyboardLayout;
extern unsigned char gPressedPhysicalKeysCount;
extern SDL_Window* gSdlWindow;
extern SDL_Surface* gSdlWindowSurface;
extern SDL_Surface* gSdlSurface;
extern SDL_Renderer* gSdlRenderer;
extern SDL_Texture* gSdlTexture;
extern SDL_Surface* gSdlTextureSurface;
int coreInit(int a1);
void coreExit();

View File

@ -259,8 +259,11 @@ static void movieDirectImpl(SDL_Surface* surface, int srcWidth, int srcHeight, i
// backbuffer surface (with palette set), all we get is shiny white box.
SDL_SetSurfacePalette(surface, gSdlSurface->format->palette);
SDL_BlitSurface(surface, &srcRect, gSdlSurface, &destRect);
SDL_BlitSurface(gSdlSurface, NULL, gSdlWindowSurface, NULL);
SDL_UpdateWindowSurface(gSdlWindow);
SDL_BlitSurface(gSdlSurface, NULL, gSdlTextureSurface, NULL);
SDL_UpdateTexture(gSdlTexture, NULL, gSdlTextureSurface->pixels, gSdlTextureSurface->pitch);
SDL_RenderClear(gSdlRenderer);
SDL_RenderCopy(gSdlRenderer, gSdlTexture, NULL, NULL);
SDL_RenderPresent(gSdlRenderer);
}
// 0x486900