Mercurial > sdl-ios-xcode
comparison test/testgles.c @ 3110:e6c21c14ce3a
Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
author | Mike Gorchak <lestat@i.com.ua> |
---|---|
date | Tue, 28 Apr 2009 04:38:51 +0000 |
parents | 82e60908fab1 |
children | 7f684f249ec9 |
comparison
equal
deleted
inserted
replaced
3109:7b3a09fb9c8b | 3110:e6c21c14ce3a |
---|---|
12 #ifdef HAVE_OPENGLES | 12 #ifdef HAVE_OPENGLES |
13 | 13 |
14 #include "SDL_opengles.h" | 14 #include "SDL_opengles.h" |
15 | 15 |
16 static CommonState *state; | 16 static CommonState *state; |
17 static SDL_GLContext context; | 17 static SDL_GLContext *context=NULL; |
18 | 18 |
19 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | 19 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
20 static void | 20 static void |
21 quit(int rc) | 21 quit(int rc) |
22 { | 22 { |
23 if (context) { | 23 int i; |
24 /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */ | 24 |
25 SDL_GL_DeleteContext(context); | 25 if (context!=NULL) |
26 } | 26 { |
27 for (i=0; i<state->num_windows; i++) | |
28 { | |
29 if (context[i]) { | |
30 SDL_GL_DeleteContext(context[i]); | |
31 } | |
32 } | |
33 | |
34 SDL_free(context); | |
35 } | |
36 | |
27 CommonQuit(state); | 37 CommonQuit(state); |
28 exit(rc); | 38 exit(rc); |
29 } | 39 } |
30 | 40 |
31 static void | 41 static void |
137 } | 147 } |
138 if (!CommonInit(state)) { | 148 if (!CommonInit(state)) { |
139 quit(2); | 149 quit(2); |
140 } | 150 } |
141 | 151 |
142 /* Create OpenGL context */ | 152 context=SDL_calloc(state->num_windows, sizeof(SDL_GLContext)); |
143 context = SDL_GL_CreateContext(state->windows[0]); | 153 if (context==NULL) |
144 if (!context) { | 154 { |
145 fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); | 155 fprintf(stderr, "Out of memory!\n"); |
146 quit(2); | 156 quit(2); |
157 } | |
158 | |
159 /* Create OpenGL ES contexts */ | |
160 for (i=0; i<state->num_windows; i++) | |
161 { | |
162 context[i] = SDL_GL_CreateContext(state->windows[i]); | |
163 if (!context[i]) { | |
164 fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); | |
165 quit(2); | |
166 } | |
147 } | 167 } |
148 | 168 |
149 if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) { | 169 if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) { |
150 SDL_GL_SetSwapInterval(1); | 170 SDL_GL_SetSwapInterval(1); |
151 } else { | 171 } else { |
163 | 183 |
164 status=SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); | 184 status=SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); |
165 if (!status) { | 185 if (!status) { |
166 printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); | 186 printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); |
167 } else { | 187 } else { |
168 printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); | 188 fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); |
169 } | 189 } |
170 status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); | 190 status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); |
171 if (!status) { | 191 if (!status) { |
172 printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); | 192 printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); |
173 } else { | 193 } else { |
174 printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); | 194 fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); |
175 } | 195 } |
176 status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); | 196 status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); |
177 if (!status) { | 197 if (!status) { |
178 printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); | 198 printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); |
179 } else { | 199 } else { |
180 printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); | 200 fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); |
181 } | 201 } |
182 status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); | 202 status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); |
183 if (!status) { | 203 if (!status) { |
184 printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); | 204 printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); |
185 } else { | 205 } else { |
186 printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); | 206 fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); |
187 } | 207 } |
188 if (fsaa) { | 208 if (fsaa) { |
189 status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); | 209 status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); |
190 if (!status) { | 210 if (!status) { |
191 printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); | 211 printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); |
192 } else { | 212 } else { |
193 printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); | 213 fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); |
194 } | 214 } |
195 status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); | 215 status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); |
196 if (!status) { | 216 if (!status) { |
197 printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); | 217 printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); |
198 } else { | 218 } else { |
199 printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError()); | 219 fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError()); |
200 } | 220 } |
201 } | 221 } |
202 if (accel) { | 222 if (accel) { |
203 status=SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); | 223 status=SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); |
204 if (!status) | 224 if (!status) |
205 { | 225 { |
206 printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); | 226 printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); |
207 } else { | 227 } else { |
208 printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError()); | 228 fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError()); |
209 } | 229 } |
210 } | 230 } |
211 | 231 |
212 /* Set rendering settings */ | 232 /* Set rendering settings for each context */ |
213 glMatrixMode(GL_PROJECTION); | 233 for (i = 0; i < state->num_windows; ++i) { |
214 glLoadIdentity(); | 234 status=SDL_GL_MakeCurrent(state->windows[i], context[i]); |
215 glOrthof(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0); | 235 if (status) |
216 glMatrixMode(GL_MODELVIEW); | 236 { |
217 glLoadIdentity(); | 237 printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); |
218 glEnable(GL_DEPTH_TEST); | 238 |
219 glDepthFunc(GL_LESS); | 239 /* Continue for next window */ |
220 glShadeModel(GL_SMOOTH); | 240 continue; |
241 } | |
242 | |
243 glMatrixMode(GL_PROJECTION); | |
244 glLoadIdentity(); | |
245 glOrthof(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0); | |
246 glMatrixMode(GL_MODELVIEW); | |
247 glLoadIdentity(); | |
248 glEnable(GL_DEPTH_TEST); | |
249 glDepthFunc(GL_LESS); | |
250 glShadeModel(GL_SMOOTH); | |
251 } | |
221 | 252 |
222 /* Main render loop */ | 253 /* Main render loop */ |
223 frames = 0; | 254 frames = 0; |
224 then = SDL_GetTicks(); | 255 then = SDL_GetTicks(); |
225 done = 0; | 256 done = 0; |
229 while (SDL_PollEvent(&event)) { | 260 while (SDL_PollEvent(&event)) { |
230 CommonEvent(state, &event, &done); | 261 CommonEvent(state, &event, &done); |
231 } | 262 } |
232 for (i = 0; i < state->num_windows; ++i) { | 263 for (i = 0; i < state->num_windows; ++i) { |
233 int w, h; | 264 int w, h; |
234 SDL_GL_MakeCurrent(state->windows[i], context); | 265 status=SDL_GL_MakeCurrent(state->windows[i], context[i]); |
266 if (status) | |
267 { | |
268 printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); | |
269 | |
270 /* Continue for next window */ | |
271 continue; | |
272 } | |
235 SDL_GetWindowSize(state->windows[i], &w, &h); | 273 SDL_GetWindowSize(state->windows[i], &w, &h); |
236 glViewport(0, 0, w, h); | 274 glViewport(0, 0, w, h); |
237 Render(); | 275 Render(); |
238 SDL_GL_SwapWindow(state->windows[i]); | 276 SDL_GL_SwapWindow(state->windows[i]); |
239 } | 277 } |