- Adapt SDL2 changes for the Mac (both using SDL2 backend and Cocoa).

This commit is contained in:
Braden Obrzut 2014-12-11 16:54:38 -05:00
parent 965d602d26
commit da8f2185d8
5 changed files with 159 additions and 70 deletions

View file

@ -560,8 +560,8 @@ set( PLAT_SDL_SPECIAL_SOURCES
sdl/i_joystick.cpp sdl/i_joystick.cpp
sdl/i_timer.cpp ) sdl/i_timer.cpp )
set( PLAT_MAC_SOURCES set( PLAT_MAC_SOURCES
sdl/iwadpicker_cocoa.mm cocoa/iwadpicker_cocoa.mm
sdl/i_system_cocoa.mm ) cocoa/i_system_cocoa.mm )
set( PLAT_COCOA_SOURCES set( PLAT_COCOA_SOURCES
cocoa/HID_Config_Utilities.c cocoa/HID_Config_Utilities.c
cocoa/HID_Error_Handler.c cocoa/HID_Error_Handler.c
@ -581,8 +581,9 @@ if( APPLE )
if( OSX_COCOA_BACKEND ) if( OSX_COCOA_BACKEND )
set( PLAT_MAC_SOURCES ${PLAT_MAC_SOURCES} ${PLAT_COCOA_SOURCES} ) set( PLAT_MAC_SOURCES ${PLAT_MAC_SOURCES} ${PLAT_COCOA_SOURCES} )
add_definitions( -DUSE_NATIVE_COCOA )
else( OSX_COCOA_BACKEND ) else( OSX_COCOA_BACKEND )
set( PLAT_MAC_SOURCES ${PLAT_MAC_SOURCES} ${PLAT_SDL_SPECIAL_SOURCES} sdl/SDLMain.m ) set( PLAT_MAC_SOURCES ${PLAT_MAC_SOURCES} ${PLAT_SDL_SPECIAL_SOURCES} )
endif( OSX_COCOA_BACKEND ) endif( OSX_COCOA_BACKEND )
set_source_files_properties( cocoa/zdoom.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources ) set_source_files_properties( cocoa/zdoom.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources )

View file

@ -1702,37 +1702,27 @@ void SDL_Quit()
} }
char* SDL_GetError() const char* SDL_GetError()
{ {
static char empty[] = {0}; static char empty[] = {0};
return empty; return empty;
} }
char* SDL_VideoDriverName(char* namebuf, int maxlen) const char* SDL_GetCurrentVideoDriver()
{ {
return strncpy(namebuf, "Native OpenGL", maxlen); return "Native OpenGL";
} }
const SDL_VideoInfo* SDL_GetVideoInfo() int SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode *mode)
{ {
// NOTE: Only required fields are assigned // NOTE: Only required fields are assigned
static SDL_PixelFormat pixelFormat;
memset(&pixelFormat, 0, sizeof(pixelFormat));
pixelFormat.BitsPerPixel = 32;
static SDL_VideoInfo videoInfo;
memset(&videoInfo, 0, sizeof(videoInfo));
const NSRect displayRect = [[NSScreen mainScreen] frame]; const NSRect displayRect = [[NSScreen mainScreen] frame];
videoInfo.current_w = displayRect.size.width; mode->w = displayRect.size.width;
videoInfo.current_h = displayRect.size.height; mode->h = displayRect.size.height;
videoInfo.vfmt = &pixelFormat;
return &videoInfo; return 0;
} }
SDL_Rect** SDL_ListModes(SDL_PixelFormat* format, Uint32 flags) SDL_Rect** SDL_ListModes(SDL_PixelFormat* format, Uint32 flags)
@ -1821,72 +1811,150 @@ static SDL_PixelFormat* GetPixelFormat()
result.Gmask = 0x0000FF00; result.Gmask = 0x0000FF00;
result.Bmask = 0x00FF0000; result.Bmask = 0x00FF0000;
result.Amask = 0xFF000000; result.Amask = 0xFF000000;
result.colorkey = 0;
result.alpha = 0xFF;
return &result; return &result;
} }
SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int* bpp, Uint32* Rmask, Uint32* Gmask, Uint32* Bmask, Uint32* Amask)
SDL_Surface* SDL_SetVideoMode(int width, int height, int, Uint32 flags)
{ {
[appCtrl changeVideoResolution:(SDL_FULLSCREEN & flags) assert(format == SDL_PIXELFORMAT_ABGR8888);
*bpp = 32;
*Rmask = 0x000000FF;
*Gmask = 0x0000FF00;
*Bmask = 0x00FF0000;
*Amask = 0xFF000000;
return SDL_TRUE;
}
struct SDL_Window
{
Uint32 flags;
int w, h;
int pitch;
void *pixels;
};
struct SDL_Renderer { SDL_Window *window; };
struct SDL_Texture { SDL_Window *window; };
SDL_Window* SDL_CreateWindow(const char* title, int x, int y, int width, int height, Uint32 flags)
{
[appCtrl changeVideoResolution:(SDL_WINDOW_FULLSCREEN_DESKTOP & flags)
width:width width:width
height:height height:height
useHiDPI:vid_hidpi]; useHiDPI:vid_hidpi];
static SDL_Surface result; static SDL_Window result;
if (!(SDL_OPENGL & flags)) if (!(SDL_WINDOW_OPENGL & flags))
{ {
[appCtrl setupSoftwareRenderingWithWidth:width [appCtrl setupSoftwareRenderingWithWidth:width
height:height]; height:height];
} }
result.flags = flags; result.flags = flags;
result.format = GetPixelFormat();
result.w = width; result.w = width;
result.h = height; result.h = height;
result.pitch = width * BYTES_PER_PIXEL; result.pitch = width * BYTES_PER_PIXEL;
result.pixels = [appCtrl softwareRenderingBuffer]; result.pixels = [appCtrl softwareRenderingBuffer];
result.refcount = 1;
result.clip_rect.x = 0;
result.clip_rect.y = 0;
result.clip_rect.w = width;
result.clip_rect.h = height;
return &result; return &result;
} }
void SDL_DestroyWindow(SDL_Window *window)
void SDL_WM_SetCaption(const char* title, const char* icon)
{ {
ZD_UNUSED(title); ZD_UNUSED(window);
ZD_UNUSED(icon);
// Window title is set in SDL_SetVideoMode()
} }
int SDL_WM_ToggleFullScreen(SDL_Surface* surface) Uint32 SDL_GetWindowFlags(SDL_Window *window)
{ {
if (surface->flags & SDL_FULLSCREEN) return window->flags;
}
SDL_Surface *SDL_GetWindowSurface(SDL_Window *window)
{ {
surface->flags &= ~SDL_FULLSCREEN; ZD_UNUSED(window);
return NULL;
}
void SDL_GetWindowSize(SDL_Window *window, int *w, int *h)
{
*w = window->w;
*h = window->h;
}
void SDL_SetWindowSize(SDL_Window *window, int w, int h)
{
// Currently this is used for handling the fullscreen->windowed transition.
// We can just no-op this for now.
ZD_UNUSED(window);
ZD_UNUSED(w);
ZD_UNUSED(h);
}
int SDL_SetWindowFullscreen(SDL_Window* window, Uint32 flags)
{
if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == (flags & SDL_WINDOW_FULLSCREEN_DESKTOP))
return 0;
if (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP)
{
window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
} }
else else
{ {
surface->flags |= SDL_FULLSCREEN; window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
} }
[appCtrl changeVideoResolution:(SDL_FULLSCREEN & surface->flags) [appCtrl changeVideoResolution:(SDL_WINDOW_FULLSCREEN_DESKTOP & flags)
width:surface->w width:window->w
height:surface->h height:window->h
useHiDPI:vid_hidpi]; useHiDPI:vid_hidpi];
return 1; return 0;
} }
SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags)
{
ZD_UNUSED(index);
ZD_UNUSED(flags);
static SDL_Renderer result;
result.window = window;
return &result;
}
void SDL_DestroyRenderer(SDL_Renderer *renderer)
{
ZD_UNUSED(renderer);
}
SDL_Texture *SDL_CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int h)
{
ZD_UNUSED(format);
ZD_UNUSED(access);
ZD_UNUSED(w);
ZD_UNUSED(h);
static SDL_Texture result;
result.window = renderer->window;
return &result;
}
void SDL_DestroyTexture(SDL_Texture *texture)
{
ZD_UNUSED(texture);
}
int SDL_QueryTexture(SDL_Texture *texture, Uint32* format, int* access, int* w, int* h)
{
if(format) *format = SDL_PIXELFORMAT_ABGR8888;
if(access) *access = SDL_TEXTUREACCESS_STREAMING;
if(w) *w = texture->window->w;
if(h) *h = texture->window->h;
return 0;
}
void SDL_GL_SwapBuffers() void SDL_GL_SwapBuffers()
{ {
@ -1918,18 +1986,22 @@ void SDL_UnlockSurface(SDL_Surface* surface)
ZD_UNUSED(surface); ZD_UNUSED(surface);
} }
int SDL_BlitSurface(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect) int SDL_LockTexture(SDL_Texture* texture, const SDL_Rect *rect, void** pixels, int *pitch)
{ {
ZD_UNUSED(src); assert(NULL == rect);
ZD_UNUSED(srcrect);
ZD_UNUSED(dst); *pixels = texture->window->pixels;
ZD_UNUSED(dstrect); *pitch = texture->window->pitch;
return 0; return 0;
} }
void SDL_UnlockTexture(SDL_Texture *texture)
{
ZD_UNUSED(texture);
}
int SDL_Flip(SDL_Surface* screen) int SDL_UpdateWindowSurface(SDL_Window *screen)
{ {
assert(NULL != screen); assert(NULL != screen);
@ -1976,10 +2048,24 @@ int SDL_Flip(SDL_Surface* screen)
return 0; return 0;
} }
int SDL_SetPalette(SDL_Surface* surface, int flags, SDL_Color* colors, int firstcolor, int ncolors) int SDL_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
{ {
ZD_UNUSED(surface); ZD_UNUSED(renderer);
ZD_UNUSED(flags); ZD_UNUSED(texture);
ZD_UNUSED(srcrect);
ZD_UNUSED(dstrect);
return 0;
}
void SDL_RenderPresent(SDL_Renderer *renderer)
{
SDL_UpdateWindowSurface(renderer->window);
}
int SDL_SetPaletteColors(SDL_Palette* palette, const SDL_Color* colors, int firstcolor, int ncolors)
{
ZD_UNUSED(palette);
ZD_UNUSED(colors); ZD_UNUSED(colors);
ZD_UNUSED(firstcolor); ZD_UNUSED(firstcolor);
ZD_UNUSED(ncolors); ZD_UNUSED(ncolors);

View file

@ -237,7 +237,11 @@ void I_ShutdownJoysticks();
const char* I_GetBackEndName(); const char* I_GetBackEndName();
#ifdef USE_NATIVE_COCOA
int SDL_main (int argc, char **argv)
#else
int main (int argc, char **argv) int main (int argc, char **argv)
#endif
{ {
#if !defined (__APPLE__) #if !defined (__APPLE__)
{ {
@ -278,9 +282,9 @@ int main (int argc, char **argv)
printf("\n"); printf("\n");
#ifdef __APPLE__ #ifdef __APPLE__
EXTERN_CVAR( Int, vid_adapter )
const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo(); SDL_DisplayMode videoInfo = {};
if ( NULL != videoInfo ) if ( SDL_GetDesktopDisplayMode (vid_adapter, &videoInfo) == 0 )
{ {
EXTERN_CVAR( Int, vid_defwidth ) EXTERN_CVAR( Int, vid_defwidth )
EXTERN_CVAR( Int, vid_defheight ) EXTERN_CVAR( Int, vid_defheight )
@ -288,13 +292,11 @@ int main (int argc, char **argv)
EXTERN_CVAR( Bool, vid_vsync ) EXTERN_CVAR( Bool, vid_vsync )
EXTERN_CVAR( Bool, fullscreen ) EXTERN_CVAR( Bool, fullscreen )
vid_defwidth = videoInfo->current_w; vid_defwidth = videoInfo.w;
vid_defheight = videoInfo->current_h; vid_defheight = videoInfo.h;
vid_defbits = videoInfo->vfmt->BitsPerPixel;
vid_vsync = true; vid_vsync = true;
fullscreen = true; fullscreen = true;
} }
#endif // __APPLE__ #endif // __APPLE__
try try