comparison src/video/SDL_video.c @ 1936:83946ee0ff1f

Implemented OpenGL support on Mac OS X The OpenGL renderer works without changes, yay! :)
author Sam Lantinga <slouken@libsdl.org>
date Tue, 25 Jul 2006 06:22:42 +0000
parents 7ee5297340f7
children 861893943d53
comparison
equal deleted inserted replaced
1935:8a9b367a80f3 1936:83946ee0ff1f
2129 } 2129 }
2130 2130
2131 int 2131 int
2132 SDL_GL_SetAttribute(SDL_GLattr attr, int value) 2132 SDL_GL_SetAttribute(SDL_GLattr attr, int value)
2133 { 2133 {
2134 #if SDL_VIDEO_OPENGL
2134 int retval; 2135 int retval;
2135 2136
2136 if (!_this) { 2137 if (!_this) {
2137 SDL_UninitializedVideo(); 2138 SDL_UninitializedVideo();
2138 return -1; 2139 return -1;
2192 SDL_SetError("Unknown OpenGL attribute"); 2193 SDL_SetError("Unknown OpenGL attribute");
2193 retval = -1; 2194 retval = -1;
2194 break; 2195 break;
2195 } 2196 }
2196 return retval; 2197 return retval;
2197 } 2198 #else
2198 2199 SDL_Unsupported();
2199 int 2200 return -1;
2200 SDL_GL_GetWindowAttribute(SDL_WindowID windowID, SDL_GLattr attr, int *value) 2201 #endif /* SDL_VIDEO_OPENGL */
2201 { 2202 }
2202 SDL_Window *window = SDL_GetWindowFromID(windowID); 2203
2203 int retval; 2204 int
2204 2205 SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
2205 if (!window) { 2206 {
2206 return -1; 2207 #if SDL_VIDEO_OPENGL
2207 } 2208 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
2208 2209 GLenum attrib = 0;
2209 if (_this->GL_GetWindowAttribute) { 2210
2210 retval = _this->GL_GetWindowAttribute(_this, window, attr, value); 2211 glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
2211 } else { 2212 if (!glGetIntegervFunc) {
2212 *value = 0; 2213 return -1;
2213 SDL_SetError("GL_GetWindowAttribute not supported"); 2214 }
2214 retval = -1; 2215 switch (attr) {
2215 } 2216 case SDL_GL_RED_SIZE:
2216 return retval; 2217 attrib = GL_RED_BITS;
2218 break;
2219 case SDL_GL_BLUE_SIZE:
2220 attrib = GL_BLUE_BITS;
2221 break;
2222 case SDL_GL_GREEN_SIZE:
2223 attrib = GL_GREEN_BITS;
2224 break;
2225 case SDL_GL_ALPHA_SIZE:
2226 attrib = GL_ALPHA_BITS;
2227 break;
2228 case SDL_GL_DOUBLEBUFFER:
2229 attrib = GL_DOUBLEBUFFER;
2230 break;
2231 case SDL_GL_DEPTH_SIZE:
2232 attrib = GL_DEPTH_BITS;
2233 break;
2234 case SDL_GL_STENCIL_SIZE:
2235 attrib = GL_STENCIL_BITS;
2236 break;
2237 case SDL_GL_ACCUM_RED_SIZE:
2238 attrib = GL_ACCUM_RED_BITS;
2239 break;
2240 case SDL_GL_ACCUM_GREEN_SIZE:
2241 attrib = GL_ACCUM_GREEN_BITS;
2242 break;
2243 case SDL_GL_ACCUM_BLUE_SIZE:
2244 attrib = GL_ACCUM_BLUE_BITS;
2245 break;
2246 case SDL_GL_ACCUM_ALPHA_SIZE:
2247 attrib = GL_ACCUM_ALPHA_BITS;
2248 break;
2249 case SDL_GL_STEREO:
2250 attrib = GL_STEREO;
2251 break;
2252 case SDL_GL_MULTISAMPLEBUFFERS:
2253 attrib = GL_SAMPLE_BUFFERS_ARB;
2254 break;
2255 case SDL_GL_MULTISAMPLESAMPLES:
2256 attrib = GL_SAMPLES_ARB;
2257 break;
2258 case SDL_GL_BUFFER_SIZE:
2259 {
2260 GLint bits = 0;
2261 GLint component;
2262
2263 /* there doesn't seem to be a single flag in OpenGL for this! */
2264 glGetIntegerv(GL_RED_BITS, &component);
2265 bits += component;
2266 glGetIntegerv(GL_GREEN_BITS, &component);
2267 bits += component;
2268 glGetIntegerv(GL_BLUE_BITS, &component);
2269 bits += component;
2270 glGetIntegerv(GL_ALPHA_BITS, &component);
2271 bits += component;
2272
2273 *value = bits;
2274 return 0;
2275 }
2276 case SDL_GL_ACCELERATED_VISUAL:
2277 {
2278 /* FIXME: How do we get this information? */
2279 *value = (_this->gl_config.accelerated != 0);
2280 return 0;
2281 }
2282 default:
2283 SDL_SetError("Unknown OpenGL attribute");
2284 return -1;
2285 }
2286
2287 glGetIntegerv(attrib, (GLint *) value);
2288 return 0;
2289 #else
2290 SDL_Unsupported();
2291 return -1;
2292 #endif /* SDL_VIDEO_OPENGL */
2217 } 2293 }
2218 2294
2219 SDL_GLContext 2295 SDL_GLContext
2220 SDL_GL_CreateContext(SDL_WindowID windowID) 2296 SDL_GL_CreateContext(SDL_WindowID windowID)
2221 { 2297 {
2237 SDL_Window *window = SDL_GetWindowFromID(windowID); 2313 SDL_Window *window = SDL_GetWindowFromID(windowID);
2238 2314
2239 if (window && !(window->flags & SDL_WINDOW_OPENGL)) { 2315 if (window && !(window->flags & SDL_WINDOW_OPENGL)) {
2240 SDL_SetError("The specified window isn't an OpenGL window"); 2316 SDL_SetError("The specified window isn't an OpenGL window");
2241 return -1; 2317 return -1;
2318 }
2319 if (!context) {
2320 window = NULL;
2242 } 2321 }
2243 return _this->GL_MakeCurrent(_this, window, context); 2322 return _this->GL_MakeCurrent(_this, window, context);
2244 } 2323 }
2245 2324
2246 int 2325 int
2294 SDL_GL_DeleteContext(SDL_GLContext context) 2373 SDL_GL_DeleteContext(SDL_GLContext context)
2295 { 2374 {
2296 if (!_this || !context) { 2375 if (!_this || !context) {
2297 return; 2376 return;
2298 } 2377 }
2378 _this->GL_MakeCurrent(_this, NULL, NULL);
2299 _this->GL_DeleteContext(_this, context); 2379 _this->GL_DeleteContext(_this, context);
2300 } 2380 }
2301 2381
2302 #if 0 // FIXME 2382 #if 0 // FIXME
2303 /* Utility function used by SDL_WM_SetIcon(); 2383 /* Utility function used by SDL_WM_SetIcon();