Skip to content

Supporting native arm builds on OSX by updating SDL to 2.26.0 #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build_deps.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
set -e

SDL_version=2.0.9
SDL2_mixer_version=2.0.4
SDL_version=2.26.0
SDL2_mixer_version=2.6.3

if [ -d ./build_ext/ ]; then
echo A directory named build_ext already exists.
Expand Down
23 changes: 17 additions & 6 deletions src/MacSrc/OpenGL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ int init_opengl() {
}

// Can we create the world rendering context?
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
context = SDL_GL_CreateContext(window);
if (context == nullptr) {
ERROR("Could not create an OpenGL context! Falling back to Software mode.");
Expand Down Expand Up @@ -444,21 +445,19 @@ void get_hdpi_scaling(int *x_scale, int *y_scale) {
*y_scale = output_height / screen_height;
}

void opengl_swap_and_restore() {
// restore the view backup (without HUD overlay) for incremental
// updates in the subsequent frame
void opengl_swap_and_restore(SDL_Surface *ui) {
SDL_GL_MakeCurrent(window, context);
SDL_GL_SwapWindow(window);

glClear(GL_COLOR_BUFFER_BIT);

int x_hdpi_scale, y_hdpi_scale;
get_hdpi_scaling(&x_hdpi_scale, &y_hdpi_scale);

// Set the drawable area for the 3d view
glViewport(phys_offset_x * x_hdpi_scale, phys_offset_y * y_hdpi_scale, phys_width * x_hdpi_scale,
phys_height * y_hdpi_scale);
set_blend_mode(false);

// Bind and setup our general shader program
glUseProgram(textureShaderProgram.shaderProgram);
GLint tcAttrib = textureShaderProgram.tcAttrib;
GLint lightAttrib = textureShaderProgram.lightAttrib;
Expand All @@ -468,6 +467,7 @@ void opengl_swap_and_restore() {
glUniformMatrix4fv(textureShaderProgram.uniView, 1, false, IdentityMatrix);
glUniformMatrix4fv(textureShaderProgram.uniProj, 1, false, IdentityMatrix);

// Draw the frame buffer to the screen as a quad
bind_texture(backupBuffer.texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Expand All @@ -487,14 +487,25 @@ void opengl_swap_and_restore() {
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();

// Finish drawing the 3d view
glFlush();

glUniform1i(textureShaderProgram.uniNightSight, false);

// check OpenGL error
// Check for OpenGL errors that might have happened
GLenum err = glGetError();
if (err != GL_NO_ERROR)
ERROR("OpenGL error: %i", err);

// Blit the UI canvas over the 3d view
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, ui);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);

SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_DestroyTexture(texture);

// Finally, swap to the screen
SDL_RenderPresent(renderer);
}

void toggle_opengl() {
Expand Down
5 changes: 3 additions & 2 deletions src/MacSrc/OpenGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern "C" {
#endif

#include <3d.h>
#include <SDL.h>

#ifdef USE_OPENGL

Expand All @@ -18,7 +19,7 @@ bool use_opengl();
void toggle_opengl();
void opengl_resize(int width, int height);
bool should_opengl_swap();
void opengl_swap_and_restore();
void opengl_swap_and_restore(SDL_Surface *ui);
void opengl_change_palette();

void opengl_set_viewport(int x, int y, int width, int height);
Expand Down Expand Up @@ -46,7 +47,7 @@ static bool use_opengl() { return false; }
static void toggle_opengl() {}
static void opengl_resize(int width, int height) {}
static bool should_opengl_swap() { return false; }
static void opengl_swap_and_restore() {}
static void opengl_swap_and_restore(SDL_Surface *ui) {}
static void opengl_change_palette() {}

static void opengl_set_viewport(int x, int y, int width, int height) {}
Expand Down
27 changes: 15 additions & 12 deletions src/MacSrc/Shock.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ void InitSDL() {
char window_title[128];
sprintf(window_title, "System Shock - %s", SHOCKOLATE_VERSION);

SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, grd_cap->w, grd_cap->h,
SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL);

Expand Down Expand Up @@ -232,7 +233,7 @@ void SetSDLPalette(int index, int count, uchar *pal) {
static bool gammalut_init = 0;
static uchar gammalut[100 - 10 + 1][256];
if (!gammalut_init) {
double factor = (can_use_opengl() ? 1.0 : 2.2); // OpenGL uses 2.2
double factor = (use_opengl() ? 1.0 : 2.2); // OpenGL uses 2.2
int i, j;
for (i = 10; i <= 100; i++) {
double gamma = (double)i * 1.0 / 100;
Expand Down Expand Up @@ -279,26 +280,28 @@ void SetSDLPalette(int index, int count, uchar *pal) {

void SDLDraw() {
if (should_opengl_swap()) {
// We want the UI background to be transparent!
sdlPalette->colors[255].a = 0x00;
}

SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, drawSurface);

if (should_opengl_swap()) {
// Draw the OpenGL view
opengl_swap_and_restore(drawSurface);

// Set the palette back, and we are done
sdlPalette->colors[255].a = 0xff;
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
return;
}

// Clear the screen!
SDL_RenderClear(renderer);
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, drawSurface);

// Blit to the screen by drawing the surface
SDL_Rect srcRect = {0, 0, gScreenWide, gScreenHigh};
SDL_RenderCopy(renderer, texture, &srcRect, NULL);
SDL_DestroyTexture(texture);

if (should_opengl_swap()) {
opengl_swap_and_restore();
} else {
SDL_RenderPresent(renderer);
SDL_RenderClear(renderer);
}
// Show everything we've drawn
SDL_RenderPresent(renderer);
}

bool MouseCaptured = FALSE;
Expand Down