Oolite
Loading...
Searching...
No Matches
OOGraphicsResetManager.m
Go to the documentation of this file.
1
/*
2
3
OOGraphicsResetManager.m
4
5
6
Copyright (C) 2007-2013 Jens Ayton and contributors
7
8
Permission is hereby granted, free of charge, to any person obtaining a copy
9
of this software and associated documentation files (the "Software"), to deal
10
in the Software without restriction, including without limitation the rights
11
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
copies of the Software, and to permit persons to whom the Software is
13
furnished to do so, subject to the following conditions:
14
15
The above copyright notice and this permission notice shall be included in all
16
copies or substantial portions of the Software.
17
18
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
SOFTWARE.
25
26
*/
27
28
#import "
OOGraphicsResetManager.h
"
29
#import "
OOOpenGLExtensionManager.h
"
30
#import "
OOTexture.h
"
31
32
static
OOGraphicsResetManager
*
sSingleton
=
nil
;
33
34
@implementation
OOGraphicsResetManager
35
36
- (void)
dealloc
37
{
38
if
(
sSingleton
==
self
)
39
sSingleton
=
nil
;
40
[clients release];
41
42
[
super
dealloc];
43
}
44
45
+ (
OOGraphicsResetManager
*)
sharedManager
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
66
- (void)
resetGraphicsState
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
76
[[
OOOpenGLExtensionManager
sharedManager
]
reset
];
77
[
OOTexture
rebindAllTextures
];
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
117
- (id)
retain
118
{
119
return
self
;
120
}
121
122
- (NSUInteger)
retainCount
123
{
124
return
UINT_MAX;
125
}
126
127
- (void)
release
128
{
129
}
130
131
- (id)
autorelease
132
{
133
return
self
;
134
}
135
136
@end
OOGraphicsResetManager.h
kOOLogException
NSString *const kOOLogException
Definition
OOLogging.m:600
OOLogOutdentIf
#define OOLogOutdentIf(class)
Definition
OOLogging.h:112
OOLog
#define OOLog(class, format,...)
Definition
OOLogging.h:84
OOLogIndentIf
#define OOLogIndentIf(class)
Definition
OOLogging.h:107
sSingleton
static OONullTexture * sSingleton
Definition
OONullTexture.m:32
OOOpenGLExtensionManager.h
OOGL
#define OOGL(statement)
Definition
OOOpenGL.h:262
nil
return nil
Definition
OOProbabilitySet.m:393
OOTexture.h
-[OOGraphicsResetManager(Singleton) release]
void release()
Definition
OOGraphicsResetManager.m:127
-[OOGraphicsResetManager(Singleton) retain]
id retain()
Definition
OOGraphicsResetManager.m:117
-[OOGraphicsResetManager(Singleton) retainCount]
NSUInteger retainCount()
Definition
OOGraphicsResetManager.m:122
-[OOGraphicsResetManager(Singleton) autorelease]
id autorelease()
Definition
OOGraphicsResetManager.m:131
OOGraphicsResetManager
Definition
OOGraphicsResetManager.h:43
OOGraphicsResetManager::clients
NSMutableSet * clients
Definition
OOGraphicsResetManager.h:45
-[OOGraphicsResetManager resetGraphicsState]
void resetGraphicsState()
Definition
OOGraphicsResetManager.m:66
+[OOGraphicsResetManager sharedManager]
OOGraphicsResetManager * sharedManager()
Definition
OOGraphicsResetManager.m:45
-[OOGraphicsResetManager dealloc]
void dealloc()
Definition
OOGraphicsResetManager.m:36
OOOpenGLExtensionManager
Definition
OOOpenGLExtensionManager.h:109
+[OOOpenGLExtensionManager sharedManager]
OOOpenGLExtensionManager * sharedManager()
Definition
OOOpenGLExtensionManager.m:323
-[OOOpenGLExtensionManager reset]
void reset()
Definition
OOOpenGLExtensionManager.m:202
OOTexture
Definition
OOTexture.h:109
+[OOTexture rebindAllTextures]
void rebindAllTextures()
Definition
OOTexture.m:350
src
Core
OOGraphicsResetManager.m
Generated by
1.15.0