comparison src/video/maccommon/SDL_macgl.c @ 0:74212992fb08

Initial revision
author Sam Lantinga <slouken@lokigames.com>
date Thu, 26 Apr 2001 16:45:43 +0000
parents
children e8157fcb3114
comparison
equal deleted inserted replaced
-1:000000000000 0:74212992fb08
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@devolution.com
21 */
22
23 #ifdef SAVE_RCSID
24 static char rcsid =
25 "@(#) $Id$";
26 #endif
27
28 /* AGL implementation of SDL OpenGL support */
29
30 #include "SDL_error.h"
31 #include "SDL_lowvideo.h"
32 #include "SDL_macgl_c.h"
33
34
35 /* krat: adding OpenGL support */
36 int Mac_GL_Init(_THIS)
37 {
38 #ifdef HAVE_OPENGL
39 AGLPixelFormat format;
40 int i = 0;
41 GLint attributes [ 24 ]; /* 24 is max possible in this setup */
42 GLboolean noerr;
43
44 attributes[i++] = AGL_RGBA;
45
46 if ( this->gl_config.double_buffer ) {
47 attributes[i++] = AGL_DOUBLEBUFFER;
48 }
49 if ( this->gl_config.depth_size != 0 ) {
50 attributes[i++] = AGL_DEPTH_SIZE;
51 attributes[i++] = this->gl_config.depth_size;
52 }
53 if ( this->gl_config.red_size != 0 &&
54 this->gl_config.blue_size != 0 &&
55 this->gl_config.green_size != 0 ) {
56
57 attributes[i++] = AGL_RED_SIZE;
58 attributes[i++] = this->gl_config.red_size;
59 attributes[i++] = AGL_GREEN_SIZE;
60 attributes[i++] = this->gl_config.green_size;
61 attributes[i++] = AGL_BLUE_SIZE;
62 attributes[i++] = this->gl_config.blue_size;
63 attributes[i++] = AGL_ALPHA_SIZE;
64 attributes[i++] = this->gl_config.alpha_size;
65 }
66 if ( this->gl_config.stencil_size != 0 ) {
67 attributes[i++] = AGL_STENCIL_SIZE;
68 attributes[i++] = this->gl_config.stencil_size;
69 }
70 if ( this->gl_config.accum_red_size != 0 &&
71 this->gl_config.accum_blue_size != 0 &&
72 this->gl_config.accum_green_size != 0 ) {
73
74 attributes[i++] = AGL_ACCUM_RED_SIZE;
75 attributes[i++] = this->gl_config.accum_red_size;
76 attributes[i++] = AGL_ACCUM_GREEN_SIZE;
77 attributes[i++] = this->gl_config.accum_green_size;
78 attributes[i++] = AGL_ACCUM_BLUE_SIZE;
79 attributes[i++] = this->gl_config.accum_blue_size;
80 attributes[i++] = AGL_ACCUM_ALPHA_SIZE;
81 attributes[i++] = this->gl_config.accum_alpha_size;
82 }
83 attributes[i++] = AGL_ALL_RENDERERS;
84 attributes[i] = AGL_NONE;
85
86 format = aglChoosePixelFormat(NULL, 0, attributes);
87 if ( format == NULL ) {
88 SDL_SetError("Couldn't match OpenGL desired format");
89 return(-1);
90 }
91
92 glContext = aglCreateContext(format, NULL);
93 if ( glContext == NULL ) {
94 SDL_SetError("Couldn't create OpenGL context");
95 return(-1);
96 }
97 aglDestroyPixelFormat(format);
98
99 #if TARGET_API_MAC_CARBON
100 noerr = aglSetDrawable(glContext, GetWindowPort(SDL_Window));
101 #else
102 noerr = aglSetDrawable(glContext, (AGLDrawable)SDL_Window);
103 #endif
104
105 if(!noerr) {
106 SDL_SetError("Unable to bind GL context to window");
107 return(-1);
108 }
109 return(0);
110 #else
111 SDL_SetError("OpenGL support not configured");
112 return(-1);
113 #endif
114 }
115
116 void Mac_GL_Quit(_THIS)
117 {
118 #ifdef HAVE_OPENGL
119 if ( glContext != NULL ) {
120 aglSetCurrentContext(NULL);
121 aglSetDrawable(glContext, NULL);
122 aglDestroyContext(glContext);
123 glContext = NULL;
124 }
125 #endif
126 }
127
128 #ifdef HAVE_OPENGL
129
130 /* Make the current context active */
131 int Mac_GL_MakeCurrent(_THIS)
132 {
133 int retval;
134
135 retval = 0;
136 if( ! aglSetCurrentContext(glContext) ) {
137 SDL_SetError("Unable to make GL context current");
138 retval = -1;
139 }
140 return(retval);
141 }
142
143 void Mac_GL_SwapBuffers(_THIS)
144 {
145 aglSwapBuffers(glContext);
146 }
147
148 #endif /* HAVE_OPENGL */
149