History

sdl: a bunch of hints and v_sync

Sigrid Solveig Haflínudóttir committed 2 years ago

Commit dd29da41 parent 42c95cd1 file · +100 −27Browse files

Unified · Split

vid_sdl.c+100−27
@@ -12,14 +12,41 @@ extern pixel_t *r_warpbuffer; · 11 unmodified lines
1212
1313 static cvar_t v_snail = {"v_snail", "0"};
1414 static cvar_t v_fullscreen = {"v_fullscreen", "0", true};
15+static cvar_t v_sync = {"v_sync", "1", true};
1516 static int oldvidbuffersz;
1617
18+static int
19+curwinmode(void)
20+{
21+ Uint32 fl;
22+
23+ fl = (win != nil ? SDL_GetWindowFlags(win) : 0) & (SDL_WINDOW_FULLSCREEN_DESKTOP|SDL_WINDOW_FULLSCREEN);
24+ if(fl == SDL_WINDOW_FULLSCREEN_DESKTOP)
25+ return 2;
26+ if(fl == SDL_WINDOW_FULLSCREEN)
27+ return 1;
28+
29+ return 0;
30+}
31+
32+static int
33+cvarwinflags(void)
34+{
35+ if(v_fullscreen.value >= 2)
36+ return SDL_WINDOW_FULLSCREEN_DESKTOP;
37+ if(v_fullscreen.value >= 1)
38+ return SDL_WINDOW_FULLSCREEN;
39+ return 0;
40+}
41+
1742 static void
1843 resetfb(void)
1944 {
2045 void *surfcache;
2146 int hunkvbuf, scachesz, n;
2247
48+ setcvar(v_fullscreen.name, va("%d", curwinmode()));
49+
2350 /* lower than 320x240 doesn't really make sense,
2451 * but at least this prevents a crash, beyond that
2552 * it's your funeral */
@@ -70,6 +97,7 @@ resetfb(void) · 44 unmodified lines
7097 memset(dvars.zbuffer, 0, hunkvbuf);
7198 surfcache = (byte *)(dvars.zbuffer + vid.width * vid.height);
7299 D_InitCaches(surfcache, scachesz);
100+ vid.resized = false;
73101 }
74102
75103 void
@@ -107,6 +135,17 @@ setpal(byte *p0) · 31 unmodified lines
107135 scr_fullupdate = 0;
108136 }
109137
138+static void
139+v_fullscreen_cb(cvar_t *var)
140+{
141+ int oldmode, mode;
142+
143+ oldmode = curwinmode();
144+ mode = var->value;
145+ if(oldmode != mode && SDL_SetWindowFullscreen(win, mode) == 0)
146+ vid.resized = true;
147+}
148+
110149 static void
111150 v_snail_cb(cvar_t *var)
112151 {
@@ -114,21 +153,64 @@ v_snail_cb(cvar_t *var) · 1 unmodified line
114153 }
115154
116155 static void
117−v_fullscreen_cb(cvar_t *var)
156+hints(void)
118157 {
119− static int oldmode = 0;
120− int mode;
121−
122− if(var->value >= 2)
123− mode = SDL_WINDOW_FULLSCREEN_DESKTOP;
124− else if(var->value >= 1)
125− mode = SDL_WINDOW_FULLSCREEN;
126− else
127− mode = 0;
128− if(oldmode != mode && SDL_SetWindowFullscreen(win, mode) == 0){
129− vid.resized = true;
130− oldmode = mode;
158+ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
159+ SDL_SetHint(SDL_HINT_VIDEO_DOUBLE_BUFFER, "1");
160+ SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "1");
161+ SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_PING, "0");
162+ SDL_SetHint(SDL_HINT_RENDER_VSYNC, v_sync.value ? "1" : "0");
163+}
164+
165+static void
166+makewindow(void)
167+{
168+ int x, y, w, h;
169+
170+ if(win != nil){
171+ SDL_GetWindowPosition(win, &x, &y);
172+ SDL_GetWindowSize(win, &w, &h);
173+ }else{
174+ x = SDL_WINDOWPOS_CENTERED;
175+ y = SDL_WINDOWPOS_CENTERED;
176+ w = 800;
177+ h = 600;
131178 }
179+
180+ if(fbi != nil)
181+ SDL_DestroyTexture(fbi);
182+ if(rend != nil)
183+ SDL_DestroyRenderer(rend);
184+ if(win != nil)
185+ SDL_DestroyWindow(win);
186+
187+ hints();
188+ win = SDL_CreateWindow("quake", x, y, w, h, cvarwinflags() | SDL_WINDOW_RESIZABLE);
189+ if(win == nil)
190+ fatal("SDL_CreateWindow: %s", SDL_GetError());
191+ SDL_SetWindowResizable(win, SDL_TRUE);
192+ SDL_SetWindowMinimumSize(win, 320, 240);
193+ rend = SDL_CreateRenderer(win, -1,
194+ (v_sync.value ? SDL_RENDERER_PRESENTVSYNC : 0) |
195+ SDL_RENDERER_SOFTWARE
196+ );
197+ if(rend == nil)
198+ fatal("SDL_CreateRenderer: %s", SDL_GetError());
199+ SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
200+ SDL_RenderClear(rend);
201+ SDL_RenderPresent(rend);
202+ vid.resized = true;
203+}
204+
205+static void
206+v_sync_cb(cvar_t *var)
207+{
208+ static int vsync;
209+
210+ if(vsync == (var->value != 0))
211+ return;
212+ vsync = var->value != 0;
213+ makewindow();
132214 }
133215
134216 void
@@ -141,23 +223,14 @@ initfb(void) · 6 unmodified lines
141223
142224 if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0)
143225 fatal("SDL_Init: %s", SDL_GetError());
144− win = SDL_CreateWindow("quake", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, 0);
145− if(win == nil)
146− fatal("SDL_CreateWindow: %s", SDL_GetError());
147− if((rend = SDL_CreateRenderer(win, -1, 0)) == NULL)
148− fatal("SDL_CreateRenderer: %s", SDL_GetError());
149− SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
150− SDL_RenderClear(rend);
151− SDL_RenderPresent(rend);
152− SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
153−
226+ makewindow();
154227 resetfb();
155− SDL_SetWindowResizable(win, SDL_TRUE);
156− SDL_SetWindowMinimumSize(win, 320, 240);
157228 IN_Grabm(1);
158229
159− Cvar_RegisterVariable(&v_snail);
230+ v_fullscreen.cb = v_fullscreen_cb;
160231 v_snail.cb = v_snail_cb;
232+ v_sync.cb = v_sync_cb;
161233 Cvar_RegisterVariable(&v_fullscreen);
162− v_fullscreen.cb = v_fullscreen_cb;
234+ Cvar_RegisterVariable(&v_snail);
235+ Cvar_RegisterVariable(&v_sync);
163236 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t