Oolite
Loading...
Searching...
No Matches
OOGraphicsResetManager.m
Go to the documentation of this file.
1/*
2
3OOGraphicsResetManager.m
4
5
6Copyright (C) 2007-2013 Jens Ayton and contributors
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25
26*/
27
30#import "OOTexture.h"
31
33
34@implementation OOGraphicsResetManager
35
36- (void)dealloc
37{
38 if (sSingleton == self)
40 [clients release];
41
42 [super dealloc];
43}
44
46{
47 if (sSingleton == nil)
48 sSingleton = [[self alloc] init];
49 return sSingleton;
50}
51
52- (void)registerClient:(id<OOGraphicsResetClient>)client
53{
54 if (client != nil) {
55 if (clients == nil)
56 clients = [[NSMutableSet alloc] init];
57 [clients addObject:[NSValue valueWithPointer:client]];
58 }
59}
60
61- (void)unregisterClient:(id<OOGraphicsResetClient>)client
62{
63 [clients removeObject:[NSValue valueWithPointer:client]];
64}
65
67{
68 NSEnumerator* clientEnum = nil;
69 id client = nil;
70
71 OOGL(glFinish());
72
73 OOLog(@"rendering.reset.start", @"%@", @"Resetting graphics state.");
74 OOLogIndentIf(@"rendering.reset.start");
75
78
79 for (clientEnum = [clients objectEnumerator]; (client = [[clientEnum nextObject] pointerValue]);) {
80 @try {
81 [client resetGraphicsState];
82 }
83 @catch (NSException* exception) {
84 OOLog(kOOLogException, @"***** EXCEPTION -- %@ : %@ -- ignored during graphics reset.", [exception name], [exception reason]);
85 }
86 }
87
88 OOLogOutdentIf(@"rendering.reset.start");
89 OOLog(@"rendering.reset.end", @"%@", @"End of graphics state reset.");
90}
91
92@end
93
94@implementation OOGraphicsResetManager (Singleton)
95
96/* Canonical singleton boilerplate.
97 See Cocoa Fundamentals Guide: Creating a Singleton Instance.
98 See also +sharedManager above.
99
100 // NOTE: assumes single-threaded first access.
101*/
102
103+ (id)allocWithZone:(NSZone*)inZone
104{
105 if (sSingleton == nil) {
106 sSingleton = [super allocWithZone:inZone];
107 return sSingleton;
108 }
109 return nil;
110}
111
112- (id)copyWithZone:(NSZone*)inZone
113{
114 return self;
115}
116
118{
119 return self;
120}
121
122- (NSUInteger)retainCount
123{
124 return UINT_MAX;
125}
126
127- (void)release
128{
129}
130
132{
133 return self;
134}
135
136@end
NSString *const kOOLogException
Definition OOLogging.m:600
#define OOLogOutdentIf(class)
Definition OOLogging.h:112
#define OOLog(class, format,...)
Definition OOLogging.h:84
#define OOLogIndentIf(class)
Definition OOLogging.h:107
static OONullTexture * sSingleton
#define OOGL(statement)
Definition OOOpenGL.h:262
return nil
OOGraphicsResetManager * sharedManager()
OOOpenGLExtensionManager * sharedManager()
void rebindAllTextures()
Definition OOTexture.m:350