-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlisting11.html
executable file
·1349 lines (1138 loc) · 49.2 KB
/
listing11.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>OpenGLMovieQT - /Carbon SetupGL/Carbon_SetupGL.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/LegacyTechnologies/index.html">Legacy Documents</a> > <a href="../../samplecode/LegacyTechnologies/idxQuickTime-date.html">QuickTime</a> > <A HREF="javascript:location.replace('index.html');">OpenGLMovieQT</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<div style="width:100%; position:fixed;"><div align="center" id="watermark" style="position: relative; margin-left:auto; margin-right:auto; z-index:20; width:500px;"><div class="legacybox"><h1>Legacy Document<span class=closebutton><a href="javascript:closeWatermark()"><img src="../../images/closebutton.png" width="14" height="14" border="0" alt="close button"></a></span></h1>
<p><strong>Important: </strong>This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.</p>
<div class="reflibtopic">
<p>Current information on this Reference Library topic can be found here:</p>
<ul>
<li><a href="http://developer.apple.com/referencelibrary/QuickTime/idxGraphicsImaging-date.html" target="_blank">QuickTime > Graphics & Imaging</a></li>
</ul>
</div>
</div></div></div>
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">OpenGLMovieQT</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/Carbon SetupGL/Carbon_SetupGL.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/Carbon Include.h</option>
<option value="listing2.html">/Carbon Resource.r</option>
<option value="listing3.html">/Carbon SetupGL/aglString/aglString.c</option>
<option value="listing4.html">/Carbon SetupGL/aglString/aglString.h</option>
<option value="listing5.html">/Carbon SetupGL/Carbon_Error_Handler.c</option>
<option value="listing6.html">/Carbon SetupGL/Carbon_Error_Handler.h</option>
<option value="listing7.html">/Carbon SetupGL/Carbon_Include.h</option>
<option value="listing8.html">/Carbon SetupGL/Carbon_Resource.r</option>
<option value="listing9.html">/Carbon SetupGL/Carbon_SetupDSp.c</option>
<option value="listing10.html">/Carbon SetupGL/Carbon_SetupDSp.h</option>
<option value="listing11.html">/Carbon SetupGL/Carbon_SetupGL.c</option>
<option value="listing12.html">/Carbon SetupGL/Carbon_SetupGL.h</option>
<option value="listing13.html">/Carbon SetupGL/Carbon_SetupGL_Test.c</option>
<option value="listing14.html">/OpenGL Movie Controls.c</option>
<option value="listing15.html">/OpenGL Movie Main.c</option>
<option value="listing16.html">/OpenGL Movie.c</option>
<option value="listing17.html">/OpenGLMovie.h</option></select>
</p>
</form>
<p><strong><a href="OpenGLMovieQT.zip">Download Sample</a></strong> (“OpenGLMovieQT.zip”, 139.4K)<BR>
<strong><a href="OpenGLMovieQT.dmg">Download Sample</a></strong> (“OpenGLMovieQT.dmg”, 197.4K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/*
File: Carbon SetupGL.c
Contains: Functions to enable building and destorying a GL full screen or windowed context
Written by: Geoff Stahl (ggs)
Copyright: Copyright © 1999 Apple Computer, Inc., All Rights Reserved
Change History (most recent first):
<4> 8/23/01 ggs Fixed texture sharing and added number of bug fixes
<3> 4/20/01 ggs Added support for texture sharing by sharing all contexts by default
<2> 3/26/01 ggs Add DSp version check and other items for full screen on X
<1> 1/19/01 ggs Initial re-add
<7> 3/22/00 ggs remove extranious prototype
<6> 3/21/00 ggs Added windowed mode and clean up various implementation details
<5> 1/26/00 ggs Add fade code back in, ensure NULL pointer/context/drawable
checks are in, add Preflight
<4> 1/24/00 ggs Added glFinish to shutdown code
<3> 1/24/00 ggs update to latest, better rendrere info handling for 3dfx, better
checks on pause and resume, added frin devce numer and gdhandle
from point
<2.7> 11/28/99 ggs Split out DSp and error handling. Added texture memory
considerations, assume VRAM is required if other than zero
<2.6> 11/14/99 ggs Fix source server copy
<2.5> 11/13/99 ggs fixed default pixel depth (0) condition that was causing failures
<2.4> 11/13/99 ggs added custom fade code
<2.3> 11/13/99 ggs Reset for Quake 3 use
<2.2> 11/12/99 ggs re-add
<2.1> 11/12/99 ggs added support for frequency retrieval, fixed display number
output to be correct if display number input was -1
<2> 11/12/99 ggs 1.0 functionality
<1> 11/11/99 ggs Initial Add
Disclaimer: You may incorporate this sample code into your applications without
restriction, though the sample code has been provided "AS IS" and the
responsibility for its operation is 100% yours. However, what you are
not permitted to do is to redistribute the source as "DSC Sample Code"
after having made changes. If you're going to re-distribute the source,
we require that you make it clear in the source that the code was
descended from Apple Sample Code, but that you've made changes.
*/
// system includes ----------------------------------------------------------
#ifdef __APPLE_CC__
#include <Carbon/Carbon.h>
#else
#include <Gestalt.h>
#include <sound.h>
#endif
// project includes ---------------------------------------------------------
#include "Carbon_Error_Handler.h"
#include "Carbon_SetupDSp.h"
#include "Carbon_SetupGL.h"
// globals (internal/private) -----------------------------------------------
const RGBColor rgbBlack = { 0x0000, 0x0000, 0x0000 };
const short kWindowType = kWindowDocumentProc;
// prototypes (internal/private) --------------------------------------------
static Boolean CheckRenderer (GDHandle hGD, long *VRAM, long *textureRAM, GLint* , Boolean fAccelMust);
static Boolean CheckAllDeviceRenderers (long* pVRAM, long* pTextureRAM, GLint* pDepthSizeSupport, Boolean fAccelMust);
static Boolean CheckWindowExtents (GDHandle hGD, short width, short height);
static void DumpCurrent (AGLDrawable* paglDraw, AGLContext* paglContext, DSpContextReference* pdspContext, pstructGLInfo pcontextInfo);
static OSStatus BuildGLContext (AGLDrawable* paglDraw, AGLContext* paglContext, DSpContextReference* pdspContext, GDHandle hGD,
pstructGLInfo pcontextInfo, AGLContext aglShareContext);
static OSStatus BuildDrawable (AGLDrawable* paglDraw, GDHandle hGD, pstructGLInfo pcontextInfo);
static OSStatus BuildGLonDevice (AGLDrawable* paglDraw, AGLContext* paglContext, DSpContextReference* pdspContext,
GDHandle hGD, pstructGLInfo pcontextInfo, AGLContext aglShareContext);
static OSStatus BuildGLonWindow (WindowPtr pWindow, AGLContext* paglContext, pstructGLWindowInfo pcontextInfo, AGLContext aglShareContext);
// functions (internal/private) ---------------------------------------------
// CheckRenderer
// looks at renderer attributes it has at least the VRAM is accelerated
// Inputs: hGD: GDHandle to device to look at
// pVRAM: pointer to VRAM in bytes required; out is actual VRAM if a renderer was found, otherwise it is the input parameter
// pTextureRAM: pointer to texture RAM in bytes required; out is same (implementation assume VRAM returned by card is total so we add texture and VRAM)
// fAccelMust: do we check for acceleration
// Returns: true if renderer for the requested device complies, false otherwise
static Boolean CheckRenderer (GDHandle hGD, long* pVRAM, long* pTextureRAM, GLint* pDepthSizeSupport, Boolean fAccelMust)
{
AGLRendererInfo info, head_info;
GLint inum;
GLint dAccel = 0;
GLint dVRAM = 0, dMaxVRAM = 0;
Boolean canAccel = false, found = false;
head_info = aglQueryRendererInfo(&hGD, 1);
aglReportError ();
if(!head_info)
{
ReportError ("aglQueryRendererInfo error");
return false;
}
else
{
info = head_info;
inum = 0;
// see if we have an accelerated renderer, if so ignore non-accelerated ones
// this prevents returning info on software renderer when actually we'll get the hardware one
while (info)
{
aglDescribeRenderer(info, AGL_ACCELERATED, &dAccel);
aglReportError ();
if (dAccel)
canAccel = true;
info = aglNextRendererInfo(info);
aglReportError ();
inum++;
}
info = head_info;
inum = 0;
while (info)
{
aglDescribeRenderer (info, AGL_ACCELERATED, &dAccel);
aglReportError ();
// if we can accel then we will choose the accelerated renderer
// how about compliant renderers???
if ((canAccel && dAccel) || (!canAccel && (!fAccelMust || dAccel)))
{
aglDescribeRenderer (info, AGL_VIDEO_MEMORY, &dVRAM); // we assume that VRAM returned is total thus add texture and VRAM required
aglReportError ();
if (dVRAM >= (*pVRAM + *pTextureRAM))
{
if (dVRAM >= dMaxVRAM) // find card with max VRAM
{
aglDescribeRenderer (info, AGL_DEPTH_MODES, pDepthSizeSupport); // which depth buffer modes are supported
aglReportError ();
dMaxVRAM = dVRAM; // store max
found = true;
}
}
}
info = aglNextRendererInfo(info);
aglReportError ();
inum++;
}
}
aglDestroyRendererInfo(head_info);
if (found) // if we found a card that has enough VRAM and meets the accel criteria
{
*pVRAM = dMaxVRAM; // return VRAM
return true;
}
// VRAM will remain to same as it did when sent in
return false;
}
//-----------------------------------------------------------------------------------------------------------------------
// CheckAllDeviceRenderers
// looks at renderer attributes and each device must have at least one renderer that fits the profile
// Inputs: pVRAM: pointer to VRAM in bytes required; out is actual min VRAM of all renderers found, otherwise it is the input parameter
// pTextureRAM: pointer to texture RAM in bytes required; out is same (implementation assume VRAM returned by card is total so we add texture and VRAM)
// fAccelMust: do we check fro acceleration
// Returns: true if any renderer for on each device complies (not necessarily the same renderer), false otherwise
static Boolean CheckAllDeviceRenderers (long* pVRAM, long* pTextureRAM, GLint* pDepthSizeSupport, Boolean fAccelMust)
{
AGLRendererInfo info, head_info;
GLint inum;
GLint dAccel = 0;
GLint dVRAM = 0, dMaxVRAM = 0;
Boolean canAccel = false, found = false, goodCheck = true; // can the renderer accelerate, did we find a valid renderer for the device, are we still successfully on all the devices looked at
long MinVRAM = 0x8FFFFFFF; // max long
GDHandle hGD = GetDeviceList (); // get the first screen
while (hGD && goodCheck)
{
head_info = aglQueryRendererInfo(&hGD, 1);
aglReportError ();
if(!head_info)
{
ReportError ("aglQueryRendererInfo error");
return false;
}
else
{
info = head_info;
inum = 0;
// see if we have an accelerated renderer, if so ignore non-accelerated ones
// this prevents returning info on software renderer when actually we'll get the hardware one
while (info)
{
aglDescribeRenderer(info, AGL_ACCELERATED, &dAccel);
aglReportError ();
if (dAccel)
canAccel = true;
info = aglNextRendererInfo(info);
aglReportError ();
inum++;
}
info = head_info;
inum = 0;
while (info)
{
aglDescribeRenderer(info, AGL_ACCELERATED, &dAccel);
aglReportError ();
// if we can accel then we will choose the accelerated renderer
// how about compliant renderers???
if ((canAccel && dAccel) || (!canAccel && (!fAccelMust || dAccel)))
{
aglDescribeRenderer(info, AGL_VIDEO_MEMORY, &dVRAM); // we assume that VRAM returned is total thus add texture and VRAM required
aglReportError ();
if (dVRAM >= (*pVRAM + *pTextureRAM))
{
if (dVRAM >= dMaxVRAM) // find card with max VRAM
{
aglDescribeRenderer(info, AGL_DEPTH_MODES, pDepthSizeSupport); // which depth buffer modes are supported
aglReportError ();
dMaxVRAM = dVRAM; // store max
found = true;
}
}
}
info = aglNextRendererInfo(info);
aglReportError ();
inum++;
}
}
aglDestroyRendererInfo(head_info);
if (found) // if we found a card that has enough VRAM and meets the accel criteria
{
if (MinVRAM > dMaxVRAM)
MinVRAM = dMaxVRAM; // return VRAM
}
else
goodCheck = false; // one device failed thus entire requirement fails
hGD = GetNextDevice (hGD); // get next device
} // while
if (goodCheck) // we check all devices and each was good
{
*pVRAM = MinVRAM; // return VRAM
return true;
}
return false; //at least one device failed to have mins
}
//-----------------------------------------------------------------------------------------------------------------------
// CheckWindowExtents
// checks to see window fits on screen completely
// Inputs: hGD: GDHandle to device to look at
// width/height: requested width and height of window
// Returns: true if window and borders fit, false otherwise
static Boolean CheckWindowExtents (GDHandle hGD, short width, short height)
{
Rect strucRect, rectWin = {0, 0, 1, 1};
short deviceHeight = (short) ((**hGD).gdRect.bottom - (**hGD).gdRect.top - GetMBarHeight ());
short deviceWidth = (short) ((**hGD).gdRect.right - (**hGD).gdRect.left);
short windowWidthExtra, windowHeightExtra;
// build window (not visible)
WindowPtr pWindow = NewCWindow (NULL, &rectWin, "\p", true, kWindowType, (WindowPtr)-1, 0, 0);
#if !TARGET_API_MAC_CARBON
strucRect = (**(((WindowPeek)pWindow)->strucRgn)).rgnBBox;
#else
GetWindowBounds (pWindow, kWindowStructureRgn, &strucRect);
#endif
windowWidthExtra = (short) ((strucRect.right - strucRect.left) - 1);
windowHeightExtra = (short) ((strucRect.bottom - strucRect.top) - 1);
DisposeWindow (pWindow);
if ((width + windowWidthExtra <= deviceWidth) &&
(height + windowHeightExtra <= deviceHeight))
return true;
return false;
}
// --------------------------------------------------------------------------
// DumpCurrent
// Kills currently allocated context
// does not care about being pretty (assumes display is likely faded)
// Inputs: paglDraw, paglContext, pdspContext: things to be destroyed
void DumpCurrent (AGLDrawable* paglDraw, AGLContext* paglContext, DSpContextReference* pdspContext, pstructGLInfo pcontextInfo)
{
if (*pdspContext)
DSpReportError (DSpContext_CustomFadeGammaOut (NULL, NULL, fadeTicks));
if (*paglContext)
{
aglSetCurrentContext (NULL);
aglReportError ();
aglSetDrawable (*paglContext, NULL);
aglReportError ();
aglDestroyContext (*paglContext);
aglReportError ();
*paglContext = NULL;
}
if (pcontextInfo->fmt)
{
aglDestroyPixelFormat (pcontextInfo->fmt); // pixel format is no longer needed
aglReportError ();
}
pcontextInfo->fmt = 0;
if (*paglDraw && !(pcontextInfo->fFullscreen && CheckMacOSX ())) // do not destory a window on DSp if in Mac OS X
// since there is no window built in X
#if TARGET_API_MAC_CARBON
DisposeWindow (GetWindowFromPort (*paglDraw));
#else
DisposeWindow ((WindowPtr) *paglDraw);
#endif
*paglDraw = NULL;
DestroyDSpContext (pdspContext); // fades in, safe to call at all times
}
#pragma mark -
// --------------------------------------------------------------------------
// BuildGLContext
// Builds OpenGL context
// Inputs: hGD: GDHandle to device to look at
// pcontextInfo: request and requirements for cotext and drawable
// Outputs: paglContext as allocated
// pcontextInfo: allocated parameters
// if fail to allocate: paglContext will be NULL
// if error: will return error paglContext will be NULL
static OSStatus BuildGLContext (AGLDrawable* paglDraw, AGLContext* paglContext, DSpContextReference* pdspContext,
GDHandle hGD, pstructGLInfo pcontextInfo, AGLContext aglShareContext)
{
OSStatus err = noErr;
NumVersion versionDSp = GetDSpVersion ();
if ((Ptr) kUnresolvedCFragSymbolAddress == (Ptr) aglChoosePixelFormat) // check for existance of OpenGL
{
ReportError ("OpenGL not installed");
return noErr;
}
// DSp has problems on Mac OS X with DSp version less than 1.99 so use agl full screen
if ((pcontextInfo->fFullscreen) && (CheckMacOSX ()) && ((versionDSp.majorRev == 0x01) && (versionDSp.minorAndBugRev < 0x99))) // need to set pixel format for full screen
{
short i = 0;
while (pcontextInfo->aglAttributes[i++] != AGL_NONE) {}
i--; // point to AGL_NONE
pcontextInfo->aglAttributes [i++] = AGL_FULLSCREEN;
pcontextInfo->aglAttributes [i++] = AGL_PIXEL_SIZE;
pcontextInfo->aglAttributes [i++] = (SInt32) pcontextInfo->pixelDepth;
pcontextInfo->aglAttributes [i++] = AGL_NONE;
}
pcontextInfo->fmt = aglChoosePixelFormat (&hGD, 1, pcontextInfo->aglAttributes); // get an appropriate pixel format
aglReportError ();
if (NULL == pcontextInfo->fmt)
{
ReportError("Could not find valid pixel format");
return noErr;
}
// using a default method of sharing all the contexts enables texture sharing across these contexts by default
*paglContext = aglCreateContext (pcontextInfo->fmt, aglShareContext); // Create an AGL context
if (AGL_BAD_MATCH == aglGetError())
*paglContext = aglCreateContext (pcontextInfo->fmt, 0); // unable to sahre context, create without sharing
aglReportError ();
if (NULL == *paglContext)
{
ReportError ("Could not create context");
return paramErr;
}
if (aglShareContext == NULL)
aglShareContext = *paglContext;
// set our drawable
// DSp has problems on Mac OS X use DSp only when version is not less than 1.99
if ((pcontextInfo->fFullscreen) && (CheckMacOSX ()) && !((versionDSp.majorRev == 0x01) && (versionDSp.minorAndBugRev < 0x99))) // fullscreen X late DSp
{
// use DSp's front buffer on Mac OS X
*paglDraw = GetDSpDrawable (*pdspContext);
// there is a problem in Mac OS X GM CoreGraphics that may not size the port pixmap correctly
// this will check the vertical sizes and offset if required to fix the problem
// this will not center ports that are smaller then a particular resolution
{
short deltaV, deltaH;
Rect portBounds;
#if TARGET_API_MAC_CARBON
PixMapHandle hPix = GetPortPixMap (*paglDraw);
Rect pixBounds = (**hPix).bounds;
GetPortBounds (*paglDraw, &portBounds);
#else
PixMapHandle hPix = (*paglDraw)->portPixMap;
Rect pixBounds = (**hPix).bounds;
portBounds = (*paglDraw)->portRect;
#endif
deltaV = (short) ((portBounds.bottom - portBounds.top) - (pixBounds.bottom - pixBounds.top) +
(portBounds.bottom - portBounds.top - pcontextInfo->height) / 2);
deltaH = (short) (-(portBounds.right - portBounds.left - pcontextInfo->width) / 2);
if (deltaV || deltaH)
{
GrafPtr pPortSave;
GetPort (&pPortSave);
SetPort ((GrafPtr)*paglDraw);
// set origin to account for CG offset and if requested drawable smaller than screen rez
SetOrigin (deltaH, deltaV);
SetPort (pPortSave);
}
}
if (!aglSetDrawable (*paglContext, *paglDraw)) // attach the CGrafPtr to the context
return aglReportError ();
}
// DSp has problems on Mac OS X with DSp version less than 1.99 so use agl full screen
else if ((pcontextInfo->fFullscreen) && (CheckMacOSX ()) && ((versionDSp.majorRev == 0x01) && (versionDSp.minorAndBugRev < 0x99))) // fulscreen X early DSp
{
// use aglFullScreen
short display = 0;
if (!aglSetFullScreen (*paglContext, pcontextInfo->width, pcontextInfo->height, 60, display)) // attach fulls screen device to the context
{
ReportError ("SetFullScreen failed");
aglReportError ();
return paramErr;
}
}
else // not Mac OS X fullscreen: this is for three cases 1) Mac OS 9 windowed 2) Mac OS X windowed 3) Mac OS 9 fullscreen (as you need to build a window on top of DSp for GL to work correctly
{
// build window as late as possible
err = BuildDrawable (paglDraw, hGD, pcontextInfo);
if (err != noErr)
{
ReportError ("Could not build drawable");
return err;
}
if (!aglSetDrawable (*paglContext, *paglDraw)) // attach the CGrafPtr to the context
return aglReportError ();
}
if(!aglSetCurrentContext (*paglContext)) // make the context the current context
return aglReportError ();
return err;
}
// --------------------------------------------------------------------------
// BuildDrawable
// Builds window to be used as drawable
// Inputs: hGD: GDHandle to device to look at
// pcontextInfo: request and requirements for cotext and drawable
// Outputs: paglDraw as allocated
// pcontextInfo: allocated parameters
// if fail to allocate: paglDraw will be NULL
// if error: will return error paglDraw will be NULL
static OSStatus BuildDrawable (AGLDrawable* paglDraw, GDHandle hGD, pstructGLInfo pcontextInfo)
{
Rect rectWin;
RGBColor rgbSave;
GrafPtr pGrafSave;
OSStatus err = noErr;
// center window in our context's gdevice
rectWin.top = (short) ((**hGD).gdRect.top + ((**hGD).gdRect.bottom - (**hGD).gdRect.top) / 2); // v center
rectWin.top -= pcontextInfo->height / 2;
rectWin.left = (short) ((**hGD).gdRect.left + ((**hGD).gdRect.right - (**hGD).gdRect.left) / 2); // h center
rectWin.left -= pcontextInfo->width / 2;
rectWin.right = (short) (rectWin.left + pcontextInfo->width);
rectWin.bottom = (short) (rectWin.top + pcontextInfo->height);
#if TARGET_API_MAC_CARBON
if (pcontextInfo->fFullscreen)
*paglDraw = GetWindowPort (NewCWindow (NULL, &rectWin, "\p", 0, plainDBox, (WindowPtr)-1, 0, 0));
else
*paglDraw = GetWindowPort (NewCWindow (NULL, &rectWin, "\p", 0, kWindowType, (WindowPtr)-1, 0, 0));
ShowWindow (GetWindowFromPort (*paglDraw));
#else
if (pcontextInfo->fFullscreen)
*paglDraw = (AGLDrawable) NewCWindow (NULL, &rectWin, "\p", 0, plainDBox, (WindowPtr)-1, 0, 0);
else
*paglDraw = (AGLDrawable) NewCWindow (NULL, &rectWin, "\p", 0, kWindowType, (WindowPtr)-1, 0, 0);
ShowWindow ((WindowPtr) *paglDraw);
#endif
GetPort (&pGrafSave);
SetPort ((GrafPtr)*paglDraw);
GetForeColor (&rgbSave);
RGBForeColor (&rgbBlack);
#if TARGET_API_MAC_CARBON
GetWindowBounds (GetWindowFromPort (*paglDraw), kWindowContentRgn, &rectWin);
#else
rectWin = ((GrafPtr) *paglDraw)->portRect;
#endif
PaintRect (&rectWin);
RGBForeColor (&rgbSave); // ensure color is reset for proper blitting
SetPort (pGrafSave);
return err;
}
// --------------------------------------------------------------------------
// BuildGLonDevice
// Takes device single device and tries to build on it
// Inputs: hGD: GDHandle to device to look at
// *pcontextInfo: request and requirements for cotext and drawable
// Outputs: *paglDraw, *paglContext and *pdspContext as allocated
// *pcontextInfo: allocated parameters
// if fail to allocate: paglDraw, paglContext and pdspContext will be NULL
// if error: will return error and paglDraw, paglContext and pdspContext will be NULL
// Note: *paglDraw and *pdspContext can be null is aglFullScreen is used
static OSStatus BuildGLonDevice (AGLDrawable* paglDraw, AGLContext* paglContext, DSpContextReference* pdspContext,
GDHandle hGD, pstructGLInfo pcontextInfo, AGLContext aglShareContext)
{
GLint depthSizeSupport;
OSStatus err = noErr;
Boolean fCheckRenderer = false;
NumVersion versionDSp = GetDSpVersion ();
if (pcontextInfo->fFullscreen)
{
// if we are in 16 or 32 bit mode already, we can check the renderer now (we will double check later)
if (16 <= (**(**hGD).gdPMap).pixelSize)
{
// check for VRAM and accelerated
if (!CheckRenderer (hGD, &(pcontextInfo->VRAM), &(pcontextInfo->textureRAM), &depthSizeSupport, pcontextInfo->fAcceleratedMust))
{
ReportError ("Renderer check failed");
return err;
}
else
fCheckRenderer = true;
}
// only for Mac OS 9 or less and greater than Mac OS X 10.0.2
// DSp has problems on Mac OS X with DSp version less than 1.99 (10.0.2 or less)
if ((!CheckMacOSX ()) || ((versionDSp.majorRev > 0x01) || ((versionDSp.majorRev == 0x01) && (versionDSp.minorAndBugRev >= 0x99)))) // DSp should be supported in version after 1.98
{
err = BuildDSpContext (pdspContext, hGD, depthSizeSupport, pcontextInfo);
// we are now faded
if ((err != noErr) || (*pdspContext == NULL))
{
if (err != noErr)
ReportErrorNum ("BuildDSpContext failed with error:", err);
else
ReportError ("Could not build DrawSprocket context");
if (*pdspContext)
DSpReportError (DSpContext_CustomFadeGammaIn (NULL, NULL, fadeTicks));
return err;
}
}
// else we are using aglFullScreen and no DSp work is required
}
else
{
if (pcontextInfo->pixelDepth == 0) // default
{
pcontextInfo->pixelDepth = (**(**hGD).gdPMap).pixelSize;
if (16 > pcontextInfo->pixelDepth)
pcontextInfo->pixelDepth = 16;
}
if (pcontextInfo->fDepthMust && (pcontextInfo->pixelDepth != (**(**hGD).gdPMap).pixelSize)) // device depth must match and does not
{
ReportError ("Pixel Depth does not match device in windowed mode.");
if (*pdspContext)
DSpReportError (DSpContext_CustomFadeGammaIn (NULL, NULL, fadeTicks));
return err;
}
// copy back the curretn depth
pcontextInfo->pixelDepth = (**(**hGD).gdPMap).pixelSize;
if (!CheckWindowExtents (hGD, pcontextInfo->width, pcontextInfo->height))
{
ReportError ("Window will not fit on device in windowed mode.");
if (*pdspContext)
DSpReportError (DSpContext_CustomFadeGammaIn (NULL, NULL, fadeTicks));
return err;
}
}
// if we have not already checked the renderer, check for VRAM and accelerated
if (!fCheckRenderer)
if (!CheckRenderer (hGD, &(pcontextInfo->VRAM), &(pcontextInfo->textureRAM), &depthSizeSupport, pcontextInfo->fAcceleratedMust))
{
ReportError ("Renderer check failed");
if (*pdspContext)
DSpReportError (DSpContext_CustomFadeGammaIn (NULL, NULL, fadeTicks));
return err;
}
// do agl
// need to send device #'s through this
err = BuildGLContext (paglDraw, paglContext, pdspContext, hGD, pcontextInfo, aglShareContext);
// DSp has problems on Mac OS X with DSp version less than 1.99
if ((!CheckMacOSX ()) || ((versionDSp.majorRev > 0x01) || ((versionDSp.majorRev == 0x01) && (versionDSp.minorAndBugRev >= 0x99))))// DSp should be supported in version after 1.98
{
if (*pdspContext)
DSpReportError (DSpContext_CustomFadeGammaIn (NULL, NULL, fadeTicks));
}
return err;
}
// --------------------------------------------------------------------------
// BuildGLonDrawable
// Takes a drawable and tries to build on it
// Inputs: aglDraw: a valid AGLDrawable
// *pcontextInfo: request and requirements for cotext and drawable
// Outputs: *paglContext as allocated
// *pcontextInfo: allocated parameters
// if fail to allocate: paglContext will be NULL
// if error: will return error and paglContext will be NULL
static OSStatus BuildGLonWindow (WindowPtr pWindow, AGLContext* paglContext, pstructGLWindowInfo pcontextInfo, AGLContext aglShareContext)
{
GDHandle hGD = NULL;
GrafPtr cgrafSave = NULL;
short numDevices;
GLint depthSizeSupport;
OSStatus err = noErr;
if (!pWindow || !pcontextInfo)
{
ReportError ("NULL parameter passed to BuildGLonDrawable.");
return paramErr;
}
GetPort (&cgrafSave);
SetPortWindowPort(pWindow);
// check renderere VRAM and acceleration
numDevices = FindGDHandleFromWindow (pWindow, &hGD);
if (!pcontextInfo->fDraggable) // if numDevices > 1 then we will only be using the software renderer otherwise check only window device
{
if ((numDevices > 1) || (numDevices == 0)) // this window spans mulitple devices thus will be software only
{
// software renderer
// infinite VRAM, infinite textureRAM, not accelerated
if (pcontextInfo->fAcceleratedMust)
{
ReportError ("Unable to accelerate window that spans multiple devices");
return err;
}
}
else // not draggable on single device
{
if (!CheckRenderer (hGD, &(pcontextInfo->VRAM), &(pcontextInfo->textureRAM), &depthSizeSupport, pcontextInfo->fAcceleratedMust))
{
ReportError ("Renderer check failed");
return err;
}
}
}
// else draggable so must check all for support (each device should have at least one renderer that meets the requirements)
else if (!CheckAllDeviceRenderers (&(pcontextInfo->VRAM), &(pcontextInfo->textureRAM), &depthSizeSupport, pcontextInfo->fAcceleratedMust))
{
ReportError ("Renderer check failed");
return err;
}
// do agl
if ((Ptr) kUnresolvedCFragSymbolAddress == (Ptr) aglChoosePixelFormat) // check for existance of OpenGL
{
ReportError ("OpenGL not installed");
return NULL;
}
// we successfully passed the renderer check
if ((!pcontextInfo->fDraggable && (numDevices == 1))) // not draggable on a single device
pcontextInfo->fmt = aglChoosePixelFormat (&hGD, 1, pcontextInfo->aglAttributes); // get an appropriate pixel format
else
pcontextInfo->fmt = aglChoosePixelFormat (NULL, 0, pcontextInfo->aglAttributes); // get an appropriate pixel format
aglReportError ();
if (NULL == pcontextInfo->fmt)
{
ReportError("Could not find valid pixel format");
return NULL;
}
*paglContext = aglCreateContext (pcontextInfo->fmt, aglShareContext); // Create an AGL context
if (AGL_BAD_MATCH == aglGetError())
*paglContext = aglCreateContext (pcontextInfo->fmt, 0); // unable to sahre context, create without sharing
aglReportError ();
if (NULL == *paglContext)
{
ReportError ("Could not create context");
return NULL;
}
if (!aglSetDrawable (*paglContext, GetWindowPort (pWindow))) // attach the CGrafPtr to the context
return aglReportError ();
if(!aglSetCurrentContext (*paglContext)) // make the context the current context
return aglReportError ();
SetPort (cgrafSave);
return err;
}
#pragma mark -
// functions (public) -------------------------------------------------------
// CheckMacOSX
// Runtime check to see if we are running on Mac OS X
// Inputs: None
// Returns: 0 if < Mac OS X or version number of Mac OS X (10.0 for GM)
UInt32 CheckMacOSX (void)
{
UInt32 response;
if ((Gestalt(gestaltSystemVersion, (SInt32 *) &response) == noErr) && (response >= 0x01000))
return response;
else
return 0;
}
// --------------------------------------------------------------------------
// PreflightGL
// Checks for presense of OpenGL and DSp (if required)
// Inputs: checkFullscreen: true if one wants to run fullscreen (which requires DrwSprocket currently)
// Ouputs: true if OpenGL is installed (and DrawSprocket if checkFullscreen is true
Boolean PreflightGL (Boolean checkFullscreen)
{
if ((Ptr) kUnresolvedCFragSymbolAddress == (Ptr) aglChoosePixelFormat) // check for existance of OpenGL
return false;
if (checkFullscreen && ((Ptr) kUnresolvedCFragSymbolAddress == (Ptr) DSpStartup)) // check for existance of DSp
return false;
return true;
}
// --------------------------------------------------------------------------
// BuildGL
// Takes device and geometry request and tries to build best context and drawable
// if device does not work will walk down devices looking for first one that satisfies requirments
// Inputs: *pnumDevice: 0 any device, # attempt that device first, then any device
// *pcontextInfo: request and requirements for cotext and drawable
// Outputs: *paglDraw, *paglContext and *pdspContext as allocated
// *pnumDevice to device number in list that was used
// *pcontextInfo: allocated parameters
// if fail to allocate: paglDraw, paglContext and pdspContext will be NULL
// if error: will return error and paglDraw, paglContext and pdspContext will be NULL
OSStatus BuildGL (AGLDrawable* paglDraw, AGLContext* paglContext, DSpContextReference* pdspContext,
short* pnumDevice, pstructGLInfo pcontextInfo, AGLContext aglShareContext)
{
OSStatus err = noErr;
GDHandle hGD = NULL;
structGLInfo contextInfoSave;
// clear
*paglDraw = NULL;
*paglContext = 0;
*pdspContext = 0;
contextInfoSave = *pcontextInfo; // save info to reset on failures
// if we are full screen and not on Mac OS X (which will use aglFullScreen)
if (pcontextInfo->fFullscreen)
{
NumVersion versionDSp = GetDSpVersion ();
// DSp has problems on Mac OS X with DSp version less than 1.99
if ((!CheckMacOSX ()) || ((versionDSp.majorRev > 0x01) || ((versionDSp.majorRev == 0x01) && (versionDSp.minorAndBugRev >= 0x99))))// DSp should be supported in version after 1.98
{
err = StartDSp ();
if (gDSpStarted)
gNeedFade = true;
else
return err;
}
}
//find main device
if (*pnumDevice == -1)
{
GDHandle hDevice; // check number of screens
hGD = GetMainDevice ();
if (NULL != hGD)
{
err = BuildGLonDevice (paglDraw, paglContext, pdspContext, hGD, pcontextInfo, aglShareContext);
// find device number
*pnumDevice = 0;
hDevice = DMGetFirstScreenDevice (true);
do
{
if (hDevice == hGD)
break;
hDevice = DMGetNextScreenDevice (hDevice, true);
(*pnumDevice)++;
}
while (hDevice);
if (!hDevice)
ReportError ("main device match not found");
}
else
ReportError ("Cannot get main device");
}
if ((err != noErr) || (*paglContext == 0))
{
err = noErr;
DumpCurrent (paglDraw, paglContext, pdspContext, pcontextInfo); // dump what ever partial solution we might have
*pcontextInfo = contextInfoSave; // restore info
//find target device and check this first is one exists
if (*pnumDevice)
{
short i;
hGD = DMGetFirstScreenDevice (true);
for (i = 0; i < *pnumDevice; i++)
{
GDHandle hGDNext = DMGetNextScreenDevice (hGD, true);
if (NULL == hGDNext) // ensure we did not run out of devices
break; // if no more devices drop out
else
hGD = hGDNext; // otherwise continue
}
*pnumDevice = i; // record device we actually got
err = BuildGLonDevice (paglDraw, paglContext, pdspContext, hGD, pcontextInfo, aglShareContext);
}
}
// while we have not allocated a context or there were errors
if ((err != noErr) || (*paglContext == 0))
{
err = noErr;
DumpCurrent (paglDraw, paglContext, pdspContext, pcontextInfo); // dump what ever partial solution we might have
*pcontextInfo = contextInfoSave; // restore info
// now look through the devices in order
hGD = DMGetFirstScreenDevice (true);
*pnumDevice = -1;
do