Commit cd61a12a authored by Mike Gorchak's avatar Mike Gorchak

Added OpenGL ES context creation for the each window which has been created...

Added OpenGL ES context creation for the each window which has been created (for --windows=N option).

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403590
parent cf3c16b2
...@@ -14,16 +14,26 @@ ...@@ -14,16 +14,26 @@
#include "SDL_opengles.h" #include "SDL_opengles.h"
static CommonState *state; static CommonState *state;
static SDL_GLContext context; static SDL_GLContext *context=NULL;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void static void
quit(int rc) quit(int rc)
{ {
if (context) { int i;
/* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
SDL_GL_DeleteContext(context); if (context!=NULL)
{
for (i=0; i<state->num_windows; i++)
{
if (context[i]) {
SDL_GL_DeleteContext(context[i]);
}
}
SDL_free(context);
} }
CommonQuit(state); CommonQuit(state);
exit(rc); exit(rc);
} }
...@@ -139,11 +149,21 @@ main(int argc, char *argv[]) ...@@ -139,11 +149,21 @@ main(int argc, char *argv[])
quit(2); quit(2);
} }
/* Create OpenGL context */ context=SDL_calloc(state->num_windows, sizeof(SDL_GLContext));
context = SDL_GL_CreateContext(state->windows[0]); if (context==NULL)
if (!context) { {
fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); fprintf(stderr, "Out of memory!\n");
quit(2); quit(2);
}
/* Create OpenGL ES contexts */
for (i=0; i<state->num_windows; i++)
{
context[i] = SDL_GL_CreateContext(state->windows[i]);
if (!context[i]) {
fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
quit(2);
}
} }
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) { if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
...@@ -165,38 +185,38 @@ main(int argc, char *argv[]) ...@@ -165,38 +185,38 @@ main(int argc, char *argv[])
if (!status) { if (!status) {
printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
} else { } else {
printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
} }
if (fsaa) { if (fsaa) {
status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
if (!status) { if (!status) {
printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
} else { } else {
printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
if (!status) { if (!status) {
printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value);
} else { } else {
printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError());
} }
} }
if (accel) { if (accel) {
...@@ -205,19 +225,30 @@ main(int argc, char *argv[]) ...@@ -205,19 +225,30 @@ main(int argc, char *argv[])
{ {
printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
} else { } else {
printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError());
} }
} }
/* Set rendering settings */ /* Set rendering settings for each context */
glMatrixMode(GL_PROJECTION); for (i = 0; i < state->num_windows; ++i) {
glLoadIdentity(); status=SDL_GL_MakeCurrent(state->windows[i], context[i]);
glOrthof(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0); if (status)
glMatrixMode(GL_MODELVIEW); {
glLoadIdentity(); printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS); /* Continue for next window */
glShadeModel(GL_SMOOTH); continue;
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glShadeModel(GL_SMOOTH);
}
/* Main render loop */ /* Main render loop */
frames = 0; frames = 0;
...@@ -231,7 +262,14 @@ main(int argc, char *argv[]) ...@@ -231,7 +262,14 @@ main(int argc, char *argv[])
} }
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
int w, h; int w, h;
SDL_GL_MakeCurrent(state->windows[i], context); status=SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status)
{
printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
/* Continue for next window */
continue;
}
SDL_GetWindowSize(state->windows[i], &w, &h); SDL_GetWindowSize(state->windows[i], &w, &h);
glViewport(0, 0, w, h); glViewport(0, 0, w, h);
Render(); Render();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment