~ubuntu-branches/ubuntu/utopic/fltk1.1/utopic

« back to all changes in this revision

Viewing changes to src/Fl_Gl_Choice.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2004-12-04 12:59:54 UTC
  • mto: (2.1.1 hoary)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041204125954-4792872ghx55a78w
Tags: upstream-1.1.6
ImportĀ upstreamĀ versionĀ 1.1.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
 
// "$Id: Fl_Gl_Choice.cxx,v 1.5.2.7.2.17 2004/04/11 04:38:57 easysw Exp $"
 
2
// "$Id: Fl_Gl_Choice.cxx,v 1.5.2.7.2.22 2004/09/24 16:00:10 easysw Exp $"
3
3
//
4
4
// OpenGL visual selection code for the Fast Light Tool Kit (FLTK).
5
5
//
30
30
#  include <FL/x.H>
31
31
#  include <stdlib.h>
32
32
#  include "Fl_Gl_Choice.H"
 
33
#  include <FL/gl_draw.H>
33
34
#  include "flstring.h"
34
35
 
35
36
#  ifdef __APPLE__
48
49
    if (g->mode == m && g->alist == alistp) 
49
50
      return g;
50
51
 
51
 
#  ifdef __APPLE__
 
52
#  ifdef __APPLE_QD__
52
53
  const int *blist;
53
54
  int list[32];
54
55
    
65
66
      list[n++] = (m & FL_RGB8) ? 8 : 1;
66
67
      if (m & FL_ALPHA) {
67
68
        list[n++] = AGL_ALPHA_SIZE;
68
 
        list[n++] = 1;
 
69
        list[n++] = (m & FL_RGB8) ? 8 : 1;
69
70
      }
70
71
      if (m & FL_ACCUM) {
71
72
        list[n++] = AGL_ACCUM_GREEN_SIZE;
96
97
  fl_open_display();
97
98
  AGLPixelFormat fmt = aglChoosePixelFormat(NULL, 0, (GLint*)blist);
98
99
  if (!fmt) return 0;
 
100
 
 
101
#elif defined(__APPLE_QUARTZ__)
 
102
  // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
 
103
  const int *blist;
 
104
  int list[32];
 
105
   
 
106
  if (alistp)
 
107
    blist = alistp;
 
108
  else {
 
109
    int n = 0;
 
110
    if (m & FL_INDEX) {
 
111
      list[n++] = AGL_BUFFER_SIZE;
 
112
      list[n++] = 8; // glut tries many sizes, but this should work...
 
113
    } else {
 
114
      list[n++] = AGL_RGBA;
 
115
      list[n++] = AGL_GREEN_SIZE;
 
116
      list[n++] = (m & FL_RGB8) ? 8 : 1;
 
117
      if (m & FL_ALPHA) {
 
118
        list[n++] = AGL_ALPHA_SIZE;
 
119
        list[n++] = (m & FL_RGB8) ? 8 : 1;
 
120
      }
 
121
      if (m & FL_ACCUM) {
 
122
        list[n++] = AGL_ACCUM_GREEN_SIZE;
 
123
        list[n++] = 1;
 
124
        if (m & FL_ALPHA) {
 
125
          list[n++] = AGL_ACCUM_ALPHA_SIZE;
 
126
          list[n++] = 1;
 
127
        }
 
128
      }
 
129
    }
 
130
    if (m & FL_DOUBLE) {
 
131
      list[n++] = AGL_DOUBLEBUFFER;
 
132
    }
 
133
    if (m & FL_DEPTH) {
 
134
      list[n++] = AGL_DEPTH_SIZE; list[n++] = 24;
 
135
    }
 
136
    if (m & FL_STENCIL) {
 
137
      list[n++] = AGL_STENCIL_SIZE; list[n++] = 1;
 
138
    }
 
139
#    ifdef AGL_STEREO
 
140
    if (m & FL_STEREO) {
 
141
      list[n++] = AGL_STEREO;
 
142
    }
 
143
#    endif
 
144
    list[n] = AGL_NONE;
 
145
    blist = list;
 
146
  }
 
147
  fl_open_display();
 
148
  AGLPixelFormat fmt = aglChoosePixelFormat(NULL, 0, (GLint*)blist);
 
149
  if (!fmt) return 0;
99
150
  
100
151
#  elif !defined(WIN32)    
101
152
 
115
166
      list[n++] = (m & FL_RGB8) ? 8 : 1;
116
167
      if (m & FL_ALPHA) {
117
168
        list[n++] = GLX_ALPHA_SIZE;
118
 
        list[n++] = 1;
 
169
        list[n++] = (m & FL_RGB8) ? 8 : 1;
119
170
      }
120
171
      if (m & FL_ACCUM) {
121
172
        list[n++] = GLX_ACCUM_GREEN_SIZE;
178
229
    if ((m & FL_STENCIL) && !pfd.cStencilBits) continue;
179
230
    // see if better than the one we have already:
180
231
    if (pixelformat) {
 
232
      // offering non-generic rendering is better (read: hardware accelleration)
 
233
      if (!(chosen_pfd.dwFlags & PFD_GENERIC_FORMAT) &&
 
234
          (pfd.dwFlags & PFD_GENERIC_FORMAT)) continue;
181
235
      // offering overlay is better:
182
 
      if (!(chosen_pfd.bReserved & 15) && (pfd.bReserved & 15)) {}
 
236
      else if (!(chosen_pfd.bReserved & 15) && (pfd.bReserved & 15)) {}
183
237
      // otherwise more bit planes is better:
184
238
      else if (chosen_pfd.cColorBits > pfd.cColorBits) continue;
185
239
      else if (chosen_pfd.cDepthBits > pfd.cDepthBits) continue;
201
255
#  ifdef WIN32
202
256
  g->pixelformat = pixelformat;
203
257
  g->pfd = chosen_pfd;
204
 
#  elif defined(__APPLE__)
 
258
#  elif defined(__APPLE_QD__)
 
259
  g->pixelformat = fmt;
 
260
#  elif defined(__APPLE_QUARTZ__)
 
261
  // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
205
262
  g->pixelformat = fmt;
206
263
#  else
207
264
  g->vis = visp;
242
299
      break;
243
300
    }
244
301
  }
 
302
  if (!nContext) gl_remove_displaylist_fonts();
245
303
}
246
304
 
247
305
#  ifdef WIN32
266
324
  return context;
267
325
}
268
326
 
269
 
#  elif defined(__APPLE__)
 
327
#  elif defined(__APPLE_QD__)
270
328
GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) {
271
329
    GLContext context, shared_ctx = context_list ? context_list[0] : 0;
272
330
    context = aglCreateContext( g->pixelformat, shared_ctx);
281
339
    aglSetDrawable( context, GetWindowPort( fl_xid(window) ) );
282
340
    return (context);
283
341
}
 
342
#  elif defined(__APPLE_QUARTZ__)
 
343
  // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
 
344
  GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) {
 
345
    GLContext context, shared_ctx = context_list ? context_list[0] : 0;
 
346
    context = aglCreateContext( g->pixelformat, shared_ctx);
 
347
    if (!context) return 0;
 
348
    add_context((GLContext)context);
 
349
    if ( window->parent() ) {
 
350
      Rect wrect; GetWindowPortBounds( fl_xid(window), &wrect );
 
351
      GLint rect[] = { window->x(), wrect.bottom-window->h()-window->y(), window->w(), window->h() };
 
352
      aglSetInteger( (GLContext)context, AGL_BUFFER_RECT, rect );
 
353
      aglEnable( (GLContext)context, AGL_BUFFER_RECT );
 
354
    }
 
355
    aglSetDrawable( context, GetWindowPort( fl_xid(window) ) );
 
356
    return (context);
 
357
}
284
358
#  else
285
359
 
286
360
GLContext fl_create_gl_context(XVisualInfo* vis) {
302
376
    cached_window = w;
303
377
#  ifdef WIN32
304
378
    wglMakeCurrent(Fl_X::i(w)->private_dc, context);
305
 
#  elif defined(__APPLE__)
 
379
#  elif defined(__APPLE_QD__)
306
380
    if ( w->parent() ) { //: resize our GL buffer rectangle
307
381
      Rect wrect; GetWindowPortBounds( fl_xid(w), &wrect );
308
382
      GLint rect[] = { w->x(), wrect.bottom-w->h()-w->y(), w->w(), w->h() };
311
385
    }
312
386
    aglSetDrawable(context, GetWindowPort( fl_xid(w) ) ); 
313
387
    aglSetCurrentContext(context);
 
388
#  elif defined(__APPLE_QUARTZ__)
 
389
    // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
 
390
    if ( w->parent() ) { //: resize our GL buffer rectangle
 
391
      Rect wrect; GetWindowPortBounds( fl_xid(w), &wrect );
 
392
      GLint rect[] = { w->x(), wrect.bottom-w->h()-w->y(), w->w(), w->h() };
 
393
      aglSetInteger( context, AGL_BUFFER_RECT, rect );
 
394
      aglEnable( context, AGL_BUFFER_RECT );
 
395
    }
 
396
    aglSetDrawable(context, GetWindowPort( fl_xid(w) ) );
 
397
    aglSetCurrentContext(context);
314
398
#  else
315
399
    glXMakeCurrent(fl_display, fl_xid(w), context);
316
400
#  endif
322
406
  cached_window = 0;
323
407
#  ifdef WIN32
324
408
  wglMakeCurrent(0, 0);
325
 
#  elif defined(__APPLE__)
 
409
#  elif defined(__APPLE_QD__)
 
410
  aglSetCurrentContext(0);
 
411
#  elif defined(__APPLE_QUARTZ__)
 
412
  // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
326
413
  aglSetCurrentContext(0);
327
414
#  else
328
415
  glXMakeCurrent(fl_display, 0, 0);
333
420
  if (cached_context == context) fl_no_gl_context();
334
421
#  ifdef WIN32
335
422
  wglDeleteContext(context);
336
 
#  elif defined(__APPLE__)
 
423
#  elif defined(__APPLE_QD__)
337
424
  aglSetCurrentContext( NULL );
338
425
  aglSetDrawable( context, NULL );    
339
426
  aglDestroyContext( context );
 
427
#  elif defined(__APPLE_QUARTZ__)
 
428
  // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
 
429
  aglSetCurrentContext( NULL );
 
430
  aglSetDrawable( context, NULL );
 
431
  aglDestroyContext( context );
340
432
#  else
341
433
  glXDestroyContext(fl_display, context);
342
434
#  endif
347
439
 
348
440
 
349
441
//
350
 
// End of "$Id: Fl_Gl_Choice.cxx,v 1.5.2.7.2.17 2004/04/11 04:38:57 easysw Exp $".
 
442
// End of "$Id: Fl_Gl_Choice.cxx,v 1.5.2.7.2.22 2004/09/24 16:00:10 easysw Exp $".
351
443
//