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
12 12
13static cvar_t v_snail = {"v_snail", "0"};13static cvar_t v_snail = {"v_snail", "0"};
14static cvar_t v_fullscreen = {"v_fullscreen", "0", true};14static cvar_t v_fullscreen = {"v_fullscreen", "0", true};
15static cvar_t v_sync = {"v_sync", "1", true};
15static int oldvidbuffersz;16static int oldvidbuffersz;
16 17
18static int
19curwinmode(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
32static int
33cvarwinflags(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
17static void42static void
18resetfb(void)43resetfb(void)
19{44{
20 void *surfcache;45 void *surfcache;
21 int hunkvbuf, scachesz, n;46 int hunkvbuf, scachesz, n;
22 47
48 setcvar(v_fullscreen.name, va("%d", curwinmode()));
49
23 /* lower than 320x240 doesn't really make sense,50 /* lower than 320x240 doesn't really make sense,
24 * but at least this prevents a crash, beyond that51 * but at least this prevents a crash, beyond that
25 * it's your funeral */52 * it's your funeral */
@@ -70,6 +97,7 @@ resetfb(void) · 44 unmodified lines
70 memset(dvars.zbuffer, 0, hunkvbuf);97 memset(dvars.zbuffer, 0, hunkvbuf);
71 surfcache = (byte *)(dvars.zbuffer + vid.width * vid.height);98 surfcache = (byte *)(dvars.zbuffer + vid.width * vid.height);
72 D_InitCaches(surfcache, scachesz);99 D_InitCaches(surfcache, scachesz);
100 vid.resized = false;
73}101}
74 102
75void103void
@@ -107,6 +135,17 @@ setpal(byte *p0) · 31 unmodified lines
107 scr_fullupdate = 0;135 scr_fullupdate = 0;
108}136}
109 137
138static void
139v_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
110static void149static void
111v_snail_cb(cvar_t *var)150v_snail_cb(cvar_t *var)
112{151{
@@ -114,21 +153,64 @@ v_snail_cb(cvar_t *var) · 1 unmodified line
114}153}
115 154
116static void155static void
117v_fullscreen_cb(cvar_t *var)156hints(void)
118{157{
119 static int oldmode = 0;158 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
120 int mode;159 SDL_SetHint(SDL_HINT_VIDEO_DOUBLE_BUFFER, "1");
121 160 SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "1");
122 if(var->value >= 2)161 SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_PING, "0");
123 mode = SDL_WINDOW_FULLSCREEN_DESKTOP;162 SDL_SetHint(SDL_HINT_RENDER_VSYNC, v_sync.value ? "1" : "0");
124 else if(var->value >= 1)163}
125 mode = SDL_WINDOW_FULLSCREEN;164
126 else165static void
127 mode = 0;166makewindow(void)
128 if(oldmode != mode && SDL_SetWindowFullscreen(win, mode) == 0){167{
129 vid.resized = true;168 int x, y, w, h;
130 oldmode = mode;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;
131 }178 }
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
205static void
206v_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();
132}214}
133 215
134void216void
@@ -141,23 +223,14 @@ initfb(void) · 6 unmodified lines
141 223
142 if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0)224 if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0)
143 fatal("SDL_Init: %s", SDL_GetError());225 fatal("SDL_Init: %s", SDL_GetError());
144 win = SDL_CreateWindow("quake", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, 0);226 makewindow();
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
154 resetfb();227 resetfb();
155 SDL_SetWindowResizable(win, SDL_TRUE);
156 SDL_SetWindowMinimumSize(win, 320, 240);
157 IN_Grabm(1);228 IN_Grabm(1);
158 229
159 Cvar_RegisterVariable(&v_snail);230 v_fullscreen.cb = v_fullscreen_cb;
160 v_snail.cb = v_snail_cb;231 v_snail.cb = v_snail_cb;
232 v_sync.cb = v_sync_cb;
161 Cvar_RegisterVariable(&v_fullscreen);233 Cvar_RegisterVariable(&v_fullscreen);
162 v_fullscreen.cb = v_fullscreen_cb;234 Cvar_RegisterVariable(&v_snail);
235 Cvar_RegisterVariable(&v_sync);
163}236}

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