@@ -22,22 +22,22 @@ @implementation GLView
2222
2323- (CVReturn) getFrameForTime : (const CVTimeStamp*)outputTime
2424{
25- // There is no autorelease pool when this method is called
26- // because it will be called from a background thread.
25+ // There is no autorelease pool when this method is called
26+ // because it will be called from a background thread.
2727 // It's important to create one or app can leak objects.
2828 @autoreleasepool {
2929 [self drawView ];
3030 }
31- return kCVReturnSuccess ;
31+ return kCVReturnSuccess ;
3232}
3333
3434// This is the renderer output callback function
3535static CVReturn MyDisplayLinkCallback (CVDisplayLinkRef displayLink,
36- const CVTimeStamp* now,
37- const CVTimeStamp* outputTime,
38- CVOptionFlags flagsIn,
39- CVOptionFlags* flagsOut,
40- void * displayLinkContext)
36+ const CVTimeStamp* now,
37+ const CVTimeStamp* outputTime,
38+ CVOptionFlags flagsIn,
39+ CVOptionFlags* flagsOut,
40+ void * displayLinkContext)
4141{
4242 CVReturn result = [(__bridge GLView*)displayLinkContext getFrameForTime: outputTime];
4343 return result;
@@ -52,30 +52,30 @@ - (void) awakeFromNib
5252 self.renderMode = Diligent::MacOSAppBase::RenderMode::OpenGL;
5353
5454 NSOpenGLPixelFormatAttribute attrs[] =
55- {
56- NSOpenGLPFADoubleBuffer ,
57- NSOpenGLPFADepthSize , 24 ,
58- NSOpenGLPFAOpenGLProfile ,
59- NSOpenGLProfileVersion4_1Core ,
60- 0
61- };
55+ {
56+ NSOpenGLPFADoubleBuffer ,
57+ NSOpenGLPFADepthSize , 24 ,
58+ NSOpenGLPFAOpenGLProfile ,
59+ NSOpenGLProfileVersion4_1Core ,
60+ 0
61+ };
6262
63- NSOpenGLPixelFormat *pf = [[NSOpenGLPixelFormat alloc ] initWithAttributes: attrs];
63+ NSOpenGLPixelFormat *pf = [[NSOpenGLPixelFormat alloc ] initWithAttributes: attrs];
6464
65- if (!pf)
66- {
67- NSLog (@" No OpenGL pixel format" );
68- }
65+ if (!pf)
66+ {
67+ NSLog (@" No OpenGL pixel format" );
68+ }
6969
7070 NSOpenGLContext * context = [[NSOpenGLContext alloc ] initWithFormat: pf shareContext: nil ];
7171
7272#if defined(DEBUG)
73- // When we're using a CoreProfile context, crash if we call a legacy OpenGL function
74- // This will make it much more obvious where and when such a function call is made so
75- // that we can remove such calls.
76- // Without this we'd simply get GL_INVALID_OPERATION error for calling legacy functions
77- // but it would be more difficult to see where that function was called.
78- CGLEnable ([context CGLContextObj ], kCGLCECrashOnRemovedFunctions );
73+ // When we're using a CoreProfile context, crash if we call a legacy OpenGL function
74+ // This will make it much more obvious where and when such a function call is made so
75+ // that we can remove such calls.
76+ // Without this we'd simply get GL_INVALID_OPERATION error for calling legacy functions
77+ // but it would be more difficult to see where that function was called.
78+ CGLEnable ([context CGLContextObj ], kCGLCECrashOnRemovedFunctions );
7979#endif
8080
8181 [self setPixelFormat: pf];
@@ -88,61 +88,61 @@ - (void) awakeFromNib
8888
8989- (void ) prepareOpenGL
9090{
91- [super prepareOpenGL ];
91+ [super prepareOpenGL ];
9292
93- // Application must be initialized before display link is started
94- [self initGL ];
93+ // Application must be initialized before display link is started
94+ [self initGL ];
9595
9696 CVDisplayLinkRef displayLink;
97- // Create a display link capable of being used with all active displays
98- CVDisplayLinkCreateWithActiveCGDisplays (&displayLink);
97+ // Create a display link capable of being used with all active displays
98+ CVDisplayLinkCreateWithActiveCGDisplays (&displayLink);
9999 [self setDisplayLink: displayLink];
100100
101- // Set the renderer output callback function
102- CVDisplayLinkSetOutputCallback (displayLink, &MyDisplayLinkCallback, (__bridge void *)self);
101+ // Set the renderer output callback function
102+ CVDisplayLinkSetOutputCallback (displayLink, &MyDisplayLinkCallback, (__bridge void *)self);
103103
104- // Set the display link for the current renderer
105- CGLContextObj cglContext = [[self openGLContext ] CGLContextObj ];
106- CGLPixelFormatObj cglPixelFormat = [[self pixelFormat ] CGLPixelFormatObj ];
107- CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext (displayLink, cglContext, cglPixelFormat);
104+ // Set the display link for the current renderer
105+ CGLContextObj cglContext = [[self openGLContext ] CGLContextObj ];
106+ CGLPixelFormatObj cglPixelFormat = [[self pixelFormat ] CGLPixelFormatObj ];
107+ CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext (displayLink, cglContext, cglPixelFormat);
108108
109- // Activate the display link
110- CVDisplayLinkStart (displayLink);
109+ // Activate the display link
110+ CVDisplayLinkStart (displayLink);
111111}
112112
113113- (void ) initGL
114114{
115- // The reshape function may have changed the thread to which our OpenGL
116- // context is attached before prepareOpenGL and initGL are called. So call
117- // makeCurrentContext to ensure that our OpenGL context current to this
118- // thread (i.e. makeCurrentContext directs all OpenGL calls on this thread
119- // to [self openGLContext])
120- [[self openGLContext ] makeCurrentContext ];
121-
122- // Synchronize buffer swaps with vertical refresh rate
123- GLint swapInt = 1 ;
124- [[self openGLContext ] setValues: &swapInt forParameter: NSOpenGLContextParameterSwapInterval ];
125-
126- // Init the application.
115+ // The reshape function may have changed the thread to which our OpenGL
116+ // context is attached before prepareOpenGL and initGL are called. So call
117+ // makeCurrentContext to ensure that our OpenGL context current to this
118+ // thread (i.e. makeCurrentContext directs all OpenGL calls on this thread
119+ // to [self openGLContext])
120+ [[self openGLContext ] makeCurrentContext ];
121+
122+ // Synchronize buffer swaps with vertical refresh rate
123+ GLint swapInt = 1 ;
124+ [[self openGLContext ] setValues: &swapInt forParameter: NSOpenGLContextParameterSwapInterval ];
125+
126+ // Init the application.
127127 [self initApp: nil ];
128128}
129129
130130- (void )reshape
131131{
132- [super reshape ];
132+ [super reshape ];
133133
134134 auto * glContext = [self openGLContext ];
135135
136- // We draw on a secondary thread through the display link. However, when
137- // resizing the view, -drawRect is called on the main thread.
138- // Add a mutex around to avoid the threads accessing the context
139- // simultaneously when resizing.
140- CGLLockContext ([glContext CGLContextObj ]);
136+ // We draw on a secondary thread through the display link. However, when
137+ // resizing the view, -drawRect is called on the main thread.
138+ // Add a mutex around to avoid the threads accessing the context
139+ // simultaneously when resizing.
140+ CGLLockContext ([glContext CGLContextObj ]);
141141
142142 [glContext makeCurrentContext ];
143143
144- // Get the view size in Points
145- NSRect viewRectPoints = [self bounds ];
144+ // Get the view size in Points
145+ NSRect viewRectPoints = [self bounds ];
146146
147147 // Rendering at retina resolutions will reduce aliasing, but at the potential
148148 // cost of framerate and battery life due to the GPU needing to render more
@@ -157,38 +157,38 @@ - (void)reshape
157157 // viewRectPixels will be the same as viewRectPoints for non-retina displays
158158 _viewRectPixels = [self convertRectToBacking: viewRectPoints];
159159
160- // Set the new dimensions in our renderer
160+ // Set the new dimensions in our renderer
161161 auto * theApp = [self lockApp ];
162162 if (theApp)
163163 {
164164 theApp->WindowResize (_viewRectPixels.size .width , _viewRectPixels.size .height );
165165 }
166166 [self unlockApp ];
167167
168- CGLUnlockContext ([glContext CGLContextObj ]);
168+ CGLUnlockContext ([glContext CGLContextObj ]);
169169}
170170
171171
172172- (void )renewGState
173173{
174- // Called whenever graphics state updated (such as window resize)
174+ // Called whenever graphics state updated (such as window resize)
175175
176- // OpenGL rendering is not synchronous with other rendering on the OSX.
177- // Therefore, call disableScreenUpdatesUntilFlush so the window server
178- // doesn't render non-OpenGL content in the window asynchronously from
179- // OpenGL content, which could cause flickering. (non-OpenGL content
180- // includes the title bar and drawing done by the app with other APIs)
181- [[self window ] disableScreenUpdatesUntilFlush ];
176+ // OpenGL rendering is not synchronous with other rendering on the OSX.
177+ // Therefore, call disableScreenUpdatesUntilFlush so the window server
178+ // doesn't render non-OpenGL content in the window asynchronously from
179+ // OpenGL content, which could cause flickering. (non-OpenGL content
180+ // includes the title bar and drawing done by the app with other APIs)
181+ [[self window ] disableScreenUpdatesUntilFlush ];
182182
183- [super renewGState ];
183+ [super renewGState ];
184184}
185185
186186- (void ) drawRect : (NSRect ) theRect
187187{
188- // Called during resize operations
188+ // Called during resize operations
189189
190- // Avoid flickering during resize by drawing
191- [self drawView ];
190+ // Avoid flickering during resize by drawing
191+ [self drawView ];
192192}
193193
194194- (void ) drawView
0 commit comments