1
0
mirror of https://github.com/thes3m/XNI synced 2024-12-26 13:26:06 +01:00
XNI/Classes/Retronator/Xni/Framework/GraphicsDeviceManager.m
Matej Jan 01f76821e6 Added a graphics device manager.
git-svn-id: http://xni.googlecode.com/svn/XNI@10 ac433895-eea3-a490-d80a-17149a75e588
2010-07-27 18:23:25 +00:00

99 lines
2.5 KiB
Objective-C

//
// GraphicsDeviceManager.m
// XNI
//
// Created by Matej Jan on 27.7.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import "GraphicsDeviceManager.h"
#import "Retronator.Xni.Framework.h"
#import "Retronator.Xni.Framework.Graphics.h"
@implementation GraphicsDeviceManager
- (id) initWithGame:(Game*)theGame {
if (self = [super init]) {
game = theGame;
deviceCreated = [[Event alloc] init];
deviceDisposing = [[Event alloc] init];
deviceReseting = [[Event alloc] init];
deviceReset = [[Event alloc] init];
[game.services addService:self ofType:[Protocols graphicsDeviceManager]];
[game.services addService:self ofType:[Protocols graphicsDeviceService]];
}
return self;
}
@synthesize graphicsProfile;
@synthesize isFullScreen;
@synthesize preferMultiSampling;
@synthesize preferedSurfaceFormat;
@synthesize preferedBackBufferWidth;
@synthesize preferedBackBufferHeight;
@synthesize preferedDepthStencilFormat;
@synthesize supportedOrientations;
@synthesize graphicsDevice;
@synthesize deviceCreated;
@synthesize deviceDisposing;
@synthesize deviceReseting;
@synthesize deviceReset;
- (void) toggleFullscreen {
isFullScreen = !isFullScreen;
[self applyChanges];
}
- (void) createDevice {
[self applyChanges];
// Listen to client size change from now on.
[game.window.clientSizeChanged
subscribeDelegate:[Delegate delegateWithTarget:self Method:@selector(applyChanges)]];
}
- (BOOL) beginDraw {
return YES;
}
- (void) endDraw {
[graphicsDevice present];
}
- (void) applyChanges {
[game.window beginScreenDeviceChangeWithFullscreen:isFullScreen];
if (graphicsDevice != nil && graphicsDevice.graphicsProfile != graphicsProfile) {
// Different graphics profile requested.
[deviceDisposing raiseWithSender:self];
[graphicsDevice release];
graphicsDevice = nil;
}
if (graphicsDevice == nil) {
// Create a new device.
graphicsDevice = [[GraphicsDevice alloc] initWithGame:game];
[game.window endScreenDeviceChange];
[deviceCreated raiseWithSender:self];
} else {
// Reset the existing device.
[deviceReseting raiseWithSender:self];
[graphicsDevice reset];
[game.window endScreenDeviceChange];
[deviceReset raiseWithSender:self];
}
}
- (void) dealloc {
[deviceDisposing raiseWithSender:self];
[graphicsDevice release];
[deviceCreated release];
[deviceDisposing release];
[deviceReseting release];
[deviceReset release];
[super dealloc];
}
@end