summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3613fc6)
raw | patch | inline | side by side (parent: 3613fc6)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 1 Apr 2020 17:37:55 +0000 (20:37 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 1 Apr 2020 17:37:55 +0000 (20:37 +0300) |
src/gl/render.c | patch | blob | history | |
src/sdl/main.c | patch | blob | history | |
src/sdl2/main.c | patch | blob | history | |
src/soft/render.c | patch | blob | history | |
src/system.h | patch | blob | history |
diff --git a/src/gl/render.c b/src/gl/render.c
index 426f43ccc1eb7ce1cf5d53723721cfe66bc5dacb..8b16371346818b370be4fa518a279c3e8d8d0520 100644 (file)
--- a/src/gl/render.c
+++ b/src/gl/render.c
assert(w > 0);
assert(h > 0);
int was = Y_videomode_setted();
- int flags = SYSTEM_USE_OPENGL;
- if (fullscreen) {
- flags |= SYSTEM_USE_FULLSCREEN;
- }
if (root != NULL) {
R_cache_free(root, 0);
root = NULL;
}
- int res = Y_set_videomode(w, h, flags);
+ int res = Y_set_videomode_opengl(w, h, fullscreen);
if (res == 0) {
if (was == 0) {
ERR_failinit("Unable to set video mode\n");
diff --git a/src/sdl/main.c b/src/sdl/main.c
index 0b1aada10b2c8886093651c5401a8fbab2eca3e9..2cc83f6409b848e56fc3d92ee72ed87142dbc610 100644 (file)
--- a/src/sdl/main.c
+++ b/src/sdl/main.c
#include "music.h" // S_initmusic S_updatemusic S_donemusic
#include "render.h" // R_init R_draw R_done
+#define MODE_NONE 0
+#define MODE_OPENGL 1
+#define MODE_SOFTWARE 2
+
static int quit = 0;
static SDL_Surface *surf = NULL;
+static int mode = MODE_NONE;
/* --- error.h --- */
/* --- system.h --- */
-int Y_set_videomode (int w, int h, int flags) {
- SDL_Surface *s;
- int colors;
- Uint32 f;
+int Y_set_videomode_opengl (int w, int h, int fullscreen) {
assert(w > 0);
assert(h > 0);
- f = SDL_DOUBLEBUF;
- if (flags & SYSTEM_USE_FULLSCREEN) {
- f = flags | SDL_FULLSCREEN;
- }
- if (flags & SYSTEM_USE_OPENGL) {
- f = flags | SDL_OPENGL;
- colors = 0;
+ Uint32 flags;
+ SDL_Surface *s;
+ if (mode == MODE_OPENGL && surf->w == w && surf->h == h && Y_get_fullscreen() == fullscreen) {
+ s = surf;
} else {
- f = flags | SDL_SWSURFACE | SDL_HWPALETTE;
- colors = 8;
+ flags = SDL_DOUBLEBUF | SDL_OPENGL;
+ if (fullscreen) {
+ flags = flags | SDL_FULLSCREEN;
+ }
+# ifdef WIN32
+ flags = flags | SDL_RESIZABLE;
+# endif
+ s = SDL_SetVideoMode(w, h, 0, flags);
+ if (s != NULL) {
+ mode = MODE_OPENGL;
+ surf = s;
+ }
}
- s = SDL_SetVideoMode(w, h, colors, f);
- if (s != NULL) {
- surf = s;
+ return s != NULL;
+}
+
+int Y_set_videomode_software (int w, int h, int fullscreen) {
+ assert(w > 0);
+ assert(h > 0);
+ Uint32 flags;
+ SDL_Surface *s;
+ if (mode == MODE_OPENGL && surf->w == w && surf->h == h && Y_get_fullscreen() == fullscreen) {
+ s = surf;
+ } else {
+ flags = SDL_DOUBLEBUF | SDL_SWSURFACE | SDL_HWPALETTE;
+ if (fullscreen) {
+ flags = flags | SDL_FULLSCREEN;
+ }
+# ifdef WIN32
+ flags = flags | SDL_RESIZABLE;
+# endif
+ s = SDL_SetVideoMode(w, h, 8, flags);
+ if (s != NULL) {
+ mode = MODE_SOFTWARE;
+ surf = s;
+ }
}
return s != NULL;
}
void Y_get_videomode (int *w, int *h) {
- if (surf != NULL) {
+ if (mode != MODE_NONE) {
*w = surf->w;
*h = surf->h;
} else {
}
int Y_videomode_setted (void) {
- return surf != NULL;
+ return mode != MODE_NONE;
}
void Y_unset_videomode (void) {
surf = NULL;
+ mode = MODE_NONE;
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
}
-void Y_set_fullscreen (int yes) {
- assert(surf != NULL);
- int flags = 0;
- if ((surf->flags & SDL_FULLSCREEN) == 0) {
- flags |= SYSTEM_USE_FULLSCREEN;
- }
- if (surf->flags & SDL_OPENGL) {
- flags |= SDL_OPENGL;
+void Y_set_fullscreen (int fullscreen) {
+ int fs = Y_get_fullscreen();
+ if (mode != MODE_NONE && fs != fullscreen) {
+ if (SDL_WM_ToggleFullScreen(surf) == 0) {
+ switch (mode) {
+ case MODE_OPENGL:
+ Y_set_videomode_opengl(surf->w, surf->h, fullscreen);
+ break;
+ case MODE_SOFTWARE:
+ Y_set_videomode_software(surf->w, surf->h, fullscreen);
+ break;
+ }
+ }
}
- Y_set_videomode(surf->w, surf->h, flags);
}
int Y_get_fullscreen (void) {
- return (surf != NULL) && ((surf->flags & SDL_FULLSCREEN) != 0);
+ return (mode != MODE_NONE) && ((surf->flags & SDL_FULLSCREEN) != 0);
}
void Y_swap_buffers (void) {
- assert(surf != NULL);
- assert(surf->flags & SDL_OPENGL);
+ assert(mode == MODE_OPENGL);
SDL_GL_SwapBuffers();
}
void Y_get_buffer (byte **buf, int *w, int *h, int *pitch) {
- assert(surf != NULL);
- assert((surf->flags & SDL_OPENGL) == 0);
+ assert(mode == MODE_SOFTWARE);
*buf = surf->pixels;
*w = surf->w;
*h = surf->h;
int i;
byte *p = vgapal;
assert(vgapal != NULL);
- assert(surf != NULL);
- assert((surf->flags & SDL_OPENGL) == 0);
+ assert(mode == MODE_SOFTWARE);
SDL_Color colors[256];
for (i = 0; i < 256; i++) {
colors[i] = (SDL_Color) {
}
void Y_repaint_rect (int x, int y, int w, int h) {
- assert(surf != NULL);
- assert((surf->flags & SDL_OPENGL) == 0);
+ assert(mode == MODE_SOFTWARE);
SDL_UpdateRect(surf, x, y, w, h);
}
void Y_repaint (void) {
- assert(surf != NULL);
- assert((surf->flags & SDL_OPENGL) == 0);
+ assert(mode == MODE_SOFTWARE);
SDL_Flip(surf);
}
case SDL_QUIT:
ERR_quit();
break;
+ case SDL_VIDEORESIZE:
+ R_set_videomode(ev.resize.w, ev.resize.h, Y_get_fullscreen());
+ break;
case SDL_KEYDOWN:
case SDL_KEYUP:
key = sdl_to_key(ev.key.keysym.sym);
diff --git a/src/sdl2/main.c b/src/sdl2/main.c
index fc50b90823a2899c36767640429e7cd64334f0c1..3f49369d326d61e8707ec99626b9edb779abd1bd 100644 (file)
--- a/src/sdl2/main.c
+++ b/src/sdl2/main.c
/* --- system.h --- */
-static int Y_set_videomode_opengl (int w, int h, int fullscreen) {
- assert(w > 0);
- assert(h > 0);
- Uint32 flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL;
- flags |= fullscreen ? SDL_WINDOW_FULLSCREEN : 0;
- // TODO set context version and type
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- int x = SDL_WINDOWPOS_CENTERED;
- int y = SDL_WINDOWPOS_CENTERED;
- SDL_Window *win = SDL_CreateWindow(TITLE_STR, x, y, w, h, flags);
- if (win != NULL) {
- SDL_GLContext ctx = SDL_GL_CreateContext(win);
- if (ctx != NULL) {
- Y_unset_videomode();
- window = win;
- context = ctx;
- SDL_GL_MakeCurrent(window, context);
- } else {
- SDL_DestroyWindow(win);
- win = NULL;
- }
- }
- return win != NULL;
-}
-
-static int Y_set_videomode_software (int w, int h, int fullscreen) {
- assert(w > 0);
- assert(h > 0);
- int x = SDL_WINDOWPOS_CENTERED;
- int y = SDL_WINDOWPOS_CENTERED;
- Uint32 flags = SDL_WINDOW_RESIZABLE;
- flags |= fullscreen ? SDL_WINDOW_FULLSCREEN : 0;
- SDL_Window *win = SDL_CreateWindow(TITLE_STR, x, y, w, h, flags);
- if (win != NULL) {
- SDL_Surface *s = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
- if (s != NULL) {
- Y_unset_videomode();
- window = win;
- surf = s;
- } else {
- SDL_DestroyWindow(win);
- win = NULL;
- }
- }
- return win != NULL;
-}
-
static int Y_resize_window (int w, int h, int fullscreen) {
assert(w > 0);
assert(h > 0);
return 1;
}
-int Y_set_videomode (int w, int h, int flags) {
+int Y_set_videomode_opengl (int w, int h, int fullscreen) {
assert(w > 0);
assert(h > 0);
- int fullscreen = (flags & SYSTEM_USE_FULLSCREEN) != 0;
- if (flags & SYSTEM_USE_OPENGL) {
- if (window != NULL && context != NULL) {
- return Y_resize_window(w, h, fullscreen);
- } else {
- return Y_set_videomode_opengl(w, h, fullscreen);
+ Uint32 flags;
+ SDL_Window *win;
+ SDL_GLContext ctx;
+ if (window != NULL && context != NULL) {
+ Y_resize_window(w, h, fullscreen);
+ win = window;
+ } else {
+ flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL;
+ if (fullscreen) {
+ flags = flags | SDL_WINDOW_FULLSCREEN;
}
+ // TODO set context version and type
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ win = SDL_CreateWindow(TITLE_STR, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, flags);
+ if (win != NULL) {
+ ctx = SDL_GL_CreateContext(win);
+ if (ctx != NULL) {
+ Y_unset_videomode();
+ window = win;
+ context = ctx;
+ SDL_GL_MakeCurrent(window, context);
+ } else {
+ SDL_DestroyWindow(win);
+ win = NULL;
+ }
+ }
+ }
+ return win != NULL;
+}
+
+int Y_set_videomode_software (int w, int h, int fullscreen) {
+ assert(w > 0);
+ assert(h > 0);
+ Uint32 flags;
+ SDL_Surface *s;
+ SDL_Window *win;
+ if (window != NULL && surf != NULL) {
+ Y_resize_window(w, h, fullscreen);
+ win = window;
} else {
- if (window != NULL && surf != NULL) {
- return Y_resize_window(w, h, fullscreen);
- } else {
- return Y_set_videomode_software(w, h, fullscreen);
+ flags = SDL_WINDOW_RESIZABLE;
+ if (fullscreen) {
+ flags = flags | SDL_WINDOW_FULLSCREEN;
+ }
+ win = SDL_CreateWindow(TITLE_STR, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, flags);
+ if (win != NULL) {
+ s = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
+ if (s != NULL) {
+ Y_unset_videomode();
+ window = win;
+ surf = s;
+ } else {
+ SDL_DestroyWindow(win);
+ win = NULL;
+ }
}
}
+ return win != NULL;
}
void Y_get_videomode (int *w, int *h) {
static void window_event_handler (SDL_WindowEvent *ev) {
switch (ev->event) {
case SDL_WINDOWEVENT_RESIZED:
- if (window != NULL && ev->windowID == SDL_GetWindowID(window)) {
- R_set_videomode(ev->data1, ev->data2, Y_get_fullscreen());
- }
+ R_set_videomode(ev->data1, ev->data2, Y_get_fullscreen());
break;
case SDL_WINDOWEVENT_CLOSE:
ERR_quit();
ERR_quit();
break;
case SDL_WINDOWEVENT:
- window_event_handler(&ev.window);
+ if (ev.window.windowID == SDL_GetWindowID(window)) {
+ window_event_handler(&ev.window);
+ }
break;
case SDL_KEYDOWN:
case SDL_KEYUP:
diff --git a/src/soft/render.c b/src/soft/render.c
index fafe379ded1be470dd0ce583a67ecb133cfe6964..74a3c0f898f2a776467ecd3c134161d82fca6e1f 100644 (file)
--- a/src/soft/render.c
+++ b/src/soft/render.c
assert(w > 0);
assert(h > 0);
int was = Y_videomode_setted();
- int res = Y_set_videomode(w, h, fullscreen ? SYSTEM_USE_FULLSCREEN : 0);
+ int res = Y_set_videomode_software(w, h, fullscreen);
if (res == 0) {
if (was == 0) {
ERR_failinit("Unable to set video mode");
diff --git a/src/system.h b/src/system.h
index 445de10cf7cbb1a8bc48bff24c0906a9b696f54c..f9de3ce940856cffd46354fe2072eca7e9a2861b 100644 (file)
--- a/src/system.h
+++ b/src/system.h
#define SYSTEM_USE_FULLSCREEN (1 << 1)
/* common video subsystem routines */
-int Y_set_videomode (int w, int h, int flags);
void Y_get_videomode (int *w, int *h);
int Y_videomode_setted (void);
void Y_unset_videomode (void);
int Y_get_fullscreen (void);
/* hardware specific rendering */
+int Y_set_videomode_opengl (int w, int h, int fullscreen);
void Y_swap_buffers (void);
/* software specific rendering */
+int Y_set_videomode_software (int w, int h, int fullscreen);
void Y_get_buffer (byte **buf, int *w, int *h, int *pitch);
void Y_set_vga_palette (byte *vgapal);
void Y_repaint_rect (int x, int y, int w, int h);
void Y_repaint (void);
-#endif /* SYSTEM_H_INCLUDED */
\ No newline at end of file
+#endif /* SYSTEM_H_INCLUDED */