src/video/quartz/SDL_QuartzGL.m
changeset 1895 c121d94672cb
parent 1738 acfd00fbff5c
     1.1 --- a/src/video/quartz/SDL_QuartzGL.m	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzGL.m	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -42,16 +42,17 @@
     1.4  #endif
     1.5  
     1.6  
     1.7 -@implementation NSOpenGLContext (CGLContextAccess)
     1.8 -- (CGLContextObj) cglContext;
     1.9 +@ implementation NSOpenGLContext (CGLContextAccess)
    1.10 +    - (CGLContextObj) cglContext;
    1.11  {
    1.12      return _contextAuxiliary;
    1.13  }
    1.14 +
    1.15  @end
    1.16 -
    1.17  /* OpenGL helper functions (used internally) */
    1.18 -
    1.19 -int QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags) {
    1.20 +    int
    1.21 +QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags)
    1.22 +{
    1.23  
    1.24      NSOpenGLPixelFormatAttribute attr[32];
    1.25      NSOpenGLPixelFormat *fmt;
    1.26 @@ -60,16 +61,16 @@
    1.27  
    1.28      /* if a GL library hasn't been loaded at this point, load the default. */
    1.29      if (!this->gl_config.driver_loaded) {
    1.30 -        if (QZ_GL_LoadLibrary(this, NULL) == -1)
    1.31 +        if (QZ_GL_LoadLibrary (this, NULL) == -1)
    1.32              return 0;
    1.33      }
    1.34  
    1.35 -    if ( flags & SDL_FULLSCREEN ) {
    1.36 +    if (flags & SDL_FULLSCREEN) {
    1.37  
    1.38          attr[i++] = NSOpenGLPFAFullScreen;
    1.39      }
    1.40      /* In windowed mode, the OpenGL pixel depth must match device pixel depth */
    1.41 -    else if ( colorBits != device_bpp ) {
    1.42 +    else if (colorBits != device_bpp) {
    1.43  
    1.44          colorBits = device_bpp;
    1.45      }
    1.46 @@ -80,39 +81,43 @@
    1.47      attr[i++] = NSOpenGLPFADepthSize;
    1.48      attr[i++] = this->gl_config.depth_size;
    1.49  
    1.50 -    if ( this->gl_config.double_buffer ) {
    1.51 +    if (this->gl_config.double_buffer) {
    1.52          attr[i++] = NSOpenGLPFADoubleBuffer;
    1.53      }
    1.54  
    1.55 -    if ( this->gl_config.stereo ) {
    1.56 +    if (this->gl_config.stereo) {
    1.57          attr[i++] = NSOpenGLPFAStereo;
    1.58      }
    1.59  
    1.60 -    if ( this->gl_config.stencil_size != 0 ) {
    1.61 +    if (this->gl_config.stencil_size != 0) {
    1.62          attr[i++] = NSOpenGLPFAStencilSize;
    1.63          attr[i++] = this->gl_config.stencil_size;
    1.64      }
    1.65  
    1.66 -    if ( (this->gl_config.accum_red_size +
    1.67 -          this->gl_config.accum_green_size +
    1.68 -          this->gl_config.accum_blue_size +
    1.69 -          this->gl_config.accum_alpha_size) > 0 ) {
    1.70 +    if ((this->gl_config.accum_red_size +
    1.71 +         this->gl_config.accum_green_size +
    1.72 +         this->gl_config.accum_blue_size +
    1.73 +         this->gl_config.accum_alpha_size) > 0) {
    1.74          attr[i++] = NSOpenGLPFAAccumSize;
    1.75 -        attr[i++] = this->gl_config.accum_red_size + this->gl_config.accum_green_size + this->gl_config.accum_blue_size + this->gl_config.accum_alpha_size;
    1.76 +        attr[i++] =
    1.77 +            this->gl_config.accum_red_size +
    1.78 +            this->gl_config.accum_green_size +
    1.79 +            this->gl_config.accum_blue_size +
    1.80 +            this->gl_config.accum_alpha_size;
    1.81      }
    1.82  
    1.83 -    if ( this->gl_config.multisamplebuffers != 0 ) {
    1.84 +    if (this->gl_config.multisamplebuffers != 0) {
    1.85          attr[i++] = NSOpenGLPFASampleBuffers;
    1.86          attr[i++] = this->gl_config.multisamplebuffers;
    1.87      }
    1.88  
    1.89 -    if ( this->gl_config.multisamplesamples != 0 ) {
    1.90 +    if (this->gl_config.multisamplesamples != 0) {
    1.91          attr[i++] = NSOpenGLPFASamples;
    1.92          attr[i++] = this->gl_config.multisamplesamples;
    1.93          attr[i++] = NSOpenGLPFANoRecovery;
    1.94      }
    1.95  
    1.96 -    if ( this->gl_config.accelerated > 0 ) {
    1.97 +    if (this->gl_config.accelerated > 0) {
    1.98          attr[i++] = NSOpenGLPFAAccelerated;
    1.99      }
   1.100  
   1.101 @@ -120,16 +125,15 @@
   1.102      attr[i++] = CGDisplayIDToOpenGLDisplayMask (display_id);
   1.103      attr[i] = 0;
   1.104  
   1.105 -    fmt = [ [ NSOpenGLPixelFormat alloc ] initWithAttributes:attr ];
   1.106 +  fmt =[[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
   1.107      if (fmt == nil) {
   1.108          SDL_SetError ("Failed creating OpenGL pixel format");
   1.109          return 0;
   1.110      }
   1.111  
   1.112 -    gl_context = [ [ NSOpenGLContext alloc ] initWithFormat:fmt
   1.113 -                                               shareContext:nil];
   1.114 +  gl_context =[[NSOpenGLContext alloc] initWithFormat: fmt shareContext:nil];
   1.115  
   1.116 -    [ fmt release ];
   1.117 +    [fmt release];
   1.118  
   1.119      if (gl_context == nil) {
   1.120          SDL_SetError ("Failed creating OpenGL context");
   1.121 @@ -141,10 +145,10 @@
   1.122       * exactly does, IMHO - for a detailed explanation see
   1.123       * http://lists.apple.com/archives/mac-opengl/2006/Jan/msg00080.html )
   1.124       */
   1.125 -    if ( this->gl_config.swap_control >= 0 ) {
   1.126 +    if (this->gl_config.swap_control >= 0) {
   1.127          long value;
   1.128          value = this->gl_config.swap_control;
   1.129 -        [ gl_context setValues: &value forParameter: NSOpenGLCPSwapInterval ];
   1.130 +      [gl_context setValues: &value forParameter:NSOpenGLCPSwapInterval];
   1.131      }
   1.132  
   1.133      /*
   1.134 @@ -155,17 +159,17 @@
   1.135       *  the OpenGL context.  The default cache size is 16."    --ryan.
   1.136       */
   1.137  
   1.138 -    #ifndef GLI_ARRAY_FUNC_CACHE_MAX
   1.139 -    #define GLI_ARRAY_FUNC_CACHE_MAX 284
   1.140 -    #endif
   1.141 +#ifndef GLI_ARRAY_FUNC_CACHE_MAX
   1.142 +#define GLI_ARRAY_FUNC_CACHE_MAX 284
   1.143 +#endif
   1.144  
   1.145 -    #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   1.146 -    #define GLI_SUBMIT_FUNC_CACHE_MAX 280
   1.147 -    #endif
   1.148 +#ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   1.149 +#define GLI_SUBMIT_FUNC_CACHE_MAX 280
   1.150 +#endif
   1.151  
   1.152      {
   1.153          long cache_max = 64;
   1.154 -        CGLContextObj ctx = [ gl_context cglContext ];
   1.155 +        CGLContextObj ctx =[gl_context cglContext];
   1.156          CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
   1.157          CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
   1.158      }
   1.159 @@ -175,11 +179,13 @@
   1.160      return 1;
   1.161  }
   1.162  
   1.163 -void QZ_TearDownOpenGL (_THIS) {
   1.164 +void
   1.165 +QZ_TearDownOpenGL (_THIS)
   1.166 +{
   1.167  
   1.168 -    [ NSOpenGLContext clearCurrentContext ];
   1.169 -    [ gl_context clearDrawable ];
   1.170 -    [ gl_context release ];
   1.171 +    [NSOpenGLContext clearCurrentContext];
   1.172 +    [gl_context clearDrawable];
   1.173 +    [gl_context release];
   1.174  }
   1.175  
   1.176  
   1.177 @@ -187,19 +193,21 @@
   1.178  static const char *DEFAULT_OPENGL_LIB_NAME =
   1.179      "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib";
   1.180  
   1.181 -int    QZ_GL_LoadLibrary    (_THIS, const char *location) {
   1.182 -    if ( gl_context != NULL ) {
   1.183 -        SDL_SetError("OpenGL context already created");
   1.184 +int
   1.185 +QZ_GL_LoadLibrary (_THIS, const char *location)
   1.186 +{
   1.187 +    if (gl_context != NULL) {
   1.188 +        SDL_SetError ("OpenGL context already created");
   1.189          return -1;
   1.190      }
   1.191  
   1.192      if (opengl_library != NULL)
   1.193 -        SDL_UnloadObject(opengl_library);
   1.194 +        SDL_UnloadObject (opengl_library);
   1.195  
   1.196      if (location == NULL)
   1.197          location = DEFAULT_OPENGL_LIB_NAME;
   1.198  
   1.199 -    opengl_library = SDL_LoadObject(location);
   1.200 +    opengl_library = SDL_LoadObject (location);
   1.201      if (opengl_library != NULL) {
   1.202          this->gl_config.driver_loaded = 1;
   1.203          return 0;
   1.204 @@ -209,73 +217,113 @@
   1.205      return -1;
   1.206  }
   1.207  
   1.208 -void*  QZ_GL_GetProcAddress (_THIS, const char *proc) {
   1.209 -    return SDL_LoadFunction(opengl_library, proc);
   1.210 +void *
   1.211 +QZ_GL_GetProcAddress (_THIS, const char *proc)
   1.212 +{
   1.213 +    return SDL_LoadFunction (opengl_library, proc);
   1.214  }
   1.215  
   1.216 -int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value) {
   1.217 +int
   1.218 +QZ_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value)
   1.219 +{
   1.220  
   1.221      GLenum attr = 0;
   1.222  
   1.223      QZ_GL_MakeCurrent (this);
   1.224  
   1.225      switch (attrib) {
   1.226 -        case SDL_GL_RED_SIZE: attr = GL_RED_BITS;   break;
   1.227 -        case SDL_GL_BLUE_SIZE: attr = GL_BLUE_BITS;  break;
   1.228 -        case SDL_GL_GREEN_SIZE: attr = GL_GREEN_BITS; break;
   1.229 -        case SDL_GL_ALPHA_SIZE: attr = GL_ALPHA_BITS; break;
   1.230 -        case SDL_GL_DOUBLEBUFFER: attr = GL_DOUBLEBUFFER; break;
   1.231 -        case SDL_GL_DEPTH_SIZE: attr = GL_DEPTH_BITS;  break;
   1.232 -        case SDL_GL_STENCIL_SIZE: attr = GL_STENCIL_BITS; break;
   1.233 -        case SDL_GL_ACCUM_RED_SIZE: attr = GL_ACCUM_RED_BITS; break;
   1.234 -        case SDL_GL_ACCUM_GREEN_SIZE: attr = GL_ACCUM_GREEN_BITS; break;
   1.235 -        case SDL_GL_ACCUM_BLUE_SIZE: attr = GL_ACCUM_BLUE_BITS; break;
   1.236 -        case SDL_GL_ACCUM_ALPHA_SIZE: attr = GL_ACCUM_ALPHA_BITS; break;
   1.237 -        case SDL_GL_STEREO: attr = GL_STEREO; break;
   1.238 -        case SDL_GL_MULTISAMPLEBUFFERS: attr = GL_SAMPLE_BUFFERS_ARB; break;
   1.239 -        case SDL_GL_MULTISAMPLESAMPLES: attr = GL_SAMPLES_ARB; break;
   1.240 -        case SDL_GL_BUFFER_SIZE:
   1.241 +    case SDL_GL_RED_SIZE:
   1.242 +        attr = GL_RED_BITS;
   1.243 +        break;
   1.244 +    case SDL_GL_BLUE_SIZE:
   1.245 +        attr = GL_BLUE_BITS;
   1.246 +        break;
   1.247 +    case SDL_GL_GREEN_SIZE:
   1.248 +        attr = GL_GREEN_BITS;
   1.249 +        break;
   1.250 +    case SDL_GL_ALPHA_SIZE:
   1.251 +        attr = GL_ALPHA_BITS;
   1.252 +        break;
   1.253 +    case SDL_GL_DOUBLEBUFFER:
   1.254 +        attr = GL_DOUBLEBUFFER;
   1.255 +        break;
   1.256 +    case SDL_GL_DEPTH_SIZE:
   1.257 +        attr = GL_DEPTH_BITS;
   1.258 +        break;
   1.259 +    case SDL_GL_STENCIL_SIZE:
   1.260 +        attr = GL_STENCIL_BITS;
   1.261 +        break;
   1.262 +    case SDL_GL_ACCUM_RED_SIZE:
   1.263 +        attr = GL_ACCUM_RED_BITS;
   1.264 +        break;
   1.265 +    case SDL_GL_ACCUM_GREEN_SIZE:
   1.266 +        attr = GL_ACCUM_GREEN_BITS;
   1.267 +        break;
   1.268 +    case SDL_GL_ACCUM_BLUE_SIZE:
   1.269 +        attr = GL_ACCUM_BLUE_BITS;
   1.270 +        break;
   1.271 +    case SDL_GL_ACCUM_ALPHA_SIZE:
   1.272 +        attr = GL_ACCUM_ALPHA_BITS;
   1.273 +        break;
   1.274 +    case SDL_GL_STEREO:
   1.275 +        attr = GL_STEREO;
   1.276 +        break;
   1.277 +    case SDL_GL_MULTISAMPLEBUFFERS:
   1.278 +        attr = GL_SAMPLE_BUFFERS_ARB;
   1.279 +        break;
   1.280 +    case SDL_GL_MULTISAMPLESAMPLES:
   1.281 +        attr = GL_SAMPLES_ARB;
   1.282 +        break;
   1.283 +    case SDL_GL_BUFFER_SIZE:
   1.284          {
   1.285              GLint bits = 0;
   1.286              GLint component;
   1.287  
   1.288              /* there doesn't seem to be a single flag in OpenGL for this! */
   1.289 -            glGetIntegerv (GL_RED_BITS, &component);   bits += component;
   1.290 -            glGetIntegerv (GL_GREEN_BITS,&component);  bits += component;
   1.291 -            glGetIntegerv (GL_BLUE_BITS, &component);  bits += component;
   1.292 -            glGetIntegerv (GL_ALPHA_BITS, &component); bits += component;
   1.293 +            glGetIntegerv (GL_RED_BITS, &component);
   1.294 +            bits += component;
   1.295 +            glGetIntegerv (GL_GREEN_BITS, &component);
   1.296 +            bits += component;
   1.297 +            glGetIntegerv (GL_BLUE_BITS, &component);
   1.298 +            bits += component;
   1.299 +            glGetIntegerv (GL_ALPHA_BITS, &component);
   1.300 +            bits += component;
   1.301  
   1.302              *value = bits;
   1.303              return 0;
   1.304          }
   1.305 -        case SDL_GL_ACCELERATED_VISUAL:
   1.306 +    case SDL_GL_ACCELERATED_VISUAL:
   1.307          {
   1.308              long val;
   1.309 -	    /* FIXME: How do we get this information here?
   1.310 -            [fmt getValues: &val forAttribute: NSOpenGLPFAAccelerated attr forVirtualScreen: 0];
   1.311 -	    */
   1.312 -	    val = (this->gl_config.accelerated != 0);;
   1.313 +            /* FIXME: How do we get this information here?
   1.314 +               [fmt getValues: &val forAttribute: NSOpenGLPFAAccelerated attr forVirtualScreen: 0];
   1.315 +             */
   1.316 +            val = (this->gl_config.accelerated != 0);;
   1.317              *value = val;
   1.318              return 0;
   1.319          }
   1.320 -        case SDL_GL_SWAP_CONTROL:
   1.321 +    case SDL_GL_SWAP_CONTROL:
   1.322          {
   1.323              long val;
   1.324 -            [ gl_context getValues: &val forParameter: NSOpenGLCPSwapInterval ];
   1.325 +          [gl_context getValues: &val forParameter:NSOpenGLCPSwapInterval];
   1.326              *value = val;
   1.327              return 0;
   1.328          }
   1.329      }
   1.330  
   1.331 -    glGetIntegerv (attr, (GLint *)value);
   1.332 +    glGetIntegerv (attr, (GLint *) value);
   1.333      return 0;
   1.334  }
   1.335  
   1.336 -int    QZ_GL_MakeCurrent    (_THIS) {
   1.337 -    [ gl_context makeCurrentContext ];
   1.338 +int
   1.339 +QZ_GL_MakeCurrent (_THIS)
   1.340 +{
   1.341 +    [gl_context makeCurrentContext];
   1.342      return 0;
   1.343  }
   1.344  
   1.345 -void   QZ_GL_SwapBuffers    (_THIS) {
   1.346 -    [ gl_context flushBuffer ];
   1.347 +void
   1.348 +QZ_GL_SwapBuffers (_THIS)
   1.349 +{
   1.350 +    [gl_context flushBuffer];
   1.351  }