1
0
mirror of https://github.com/thes3m/XNI synced 2024-12-26 13:26:06 +01:00

Added support for preferedBackBufferWidth and Height.

git-svn-id: http://xni.googlecode.com/svn/XNI@56 ac433895-eea3-a490-d80a-17149a75e588
This commit is contained in:
Matej Jan 2011-02-04 22:19:35 +00:00
parent 74ccf177c5
commit 216ff5773a
13 changed files with 72 additions and 17 deletions

View File

@ -25,6 +25,7 @@
effect.specularColor = content.specularColor;
effect.emissiveColor = content.emissiveColor;
effect.texture = [input readSharedResourceFrom:content.texture];
NSLog(@"loaded: %i", [effect.texture retainCount]);
effect.textureEnabled = effect.texture != nil;
return effect;

View File

@ -83,7 +83,7 @@
// Check if we have already loaded this file.
id existing = [loadedFiles objectForKey:filePath];
if (existing) {
return existing;
return [existing retain]; // TODO: Expecting a retained object crap! Remove when proper.
}
// Find extension and absolute path.

View File

@ -18,6 +18,8 @@
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
ModelMeshContent *content = input.content;
NSLog(@"Mesh: %@", content.name);
// Create all model mesh parts.
NSMutableArray *meshParts = [NSMutableArray array];
for (ModelMeshPartContent *meshPartContent in content.meshParts) {

View File

@ -10,11 +10,13 @@
#import <QuartzCore/QuartzCore.h>
#import "Retronator.Xni.Framework.h"
#import "Retronator.Xni.Framework.Media.h"
@implementation GameHost
- (id) init {
if (self = [super init]) {
[MediaPlayer load];
window = [[GameWindow alloc] init];
}
return self;

View File

@ -11,15 +11,15 @@
@implementation GameView
- (id) initWithFrame:(CGRect)frame {
- (id) initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
viewSizeChanged = [[Event alloc] init];
CAEAGLLayer *eaglLayer = (CAEAGLLayer*)self.layer;
eaglLayer.contentsScale = [UIScreen mainScreen].scale;
eaglLayer.opaque = TRUE;
//eaglLayer.contentsScale = [UIScreen mainScreen].scale;
eaglLayer.opaque = YES;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking,
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];

View File

@ -102,7 +102,7 @@
[self dismissModalViewControllerAnimated:YES];
}
- (void)loadView {
- (void)loadView {
GameView *gameView = [[GameView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
self.view = gameView;

View File

@ -31,7 +31,7 @@
@property (nonatomic, readonly) Event *orientationChanged;
- (void) beginScreenDeviceChangeWithFullscreen:(BOOL)willBeFullscreen;
- (void) endScreenDeviceChange;
- (void) endScreenDeviceChangeWithClientWidth:(int)clientWidth clientHeight:(int)clientHeight;
- (void) setSupportedOrientations:(DisplayOrientation)orientations;

View File

@ -59,13 +59,50 @@
- (void) beginScreenDeviceChangeWithFullscreen:(BOOL)willBeFullscreen {
gameViewController.wantsFullScreenLayout = willBeFullscreen;
[[UIApplication sharedApplication] setStatusBarHidden:willBeFullscreen];
gameViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[clientBounds release];
clientBounds = [[self calculateClientBounds] retain];
}
- (void) endScreenDeviceChange {
- (void) endScreenDeviceChangeWithClientWidth:(int)clientWidth clientHeight:(int)clientHeight {
CGRect realFrame = [UIScreen mainScreen].applicationFrame;
float realAspectRatio = realFrame.size.width / realFrame.size.height;
if (clientWidth == 0) {
clientWidth = realFrame.size.width;
}
if (clientHeight == 0) {
clientHeight = realFrame.size.height;
}
float targetAspectRatio = (float)clientWidth/(float)clientHeight;
CGRect targetFrame;
if (targetAspectRatio >= realAspectRatio) {
// Add black borders on top and bottom.
targetFrame.size.width = realFrame.size.width;
targetFrame.size.height = targetFrame.size.width / targetAspectRatio;
} else {
// Add black borders on left and right.
targetFrame.size.height = realFrame.size.height;
targetFrame.size.width = targetFrame.size.height * targetAspectRatio;
}
// Center the window.
targetFrame.origin.x = realFrame.origin.x + (realFrame.size.width - targetFrame.size.width) / 2;
targetFrame.origin.y = realFrame.origin.y + (realFrame.size.height - targetFrame.size.height) / 2;
// Resize the target view.
gameViewController.view.frame = targetFrame;
// Recalculate client bounds.
[clientBounds release];
clientBounds = [[self calculateClientBounds] retain];
// Set scale factor.
if (targetAspectRatio >= realAspectRatio) {
gameViewController.view.contentScaleFactor = clientWidth / realFrame.size.width;
} else {
gameViewController.view.contentScaleFactor = clientHeight / realFrame.size.height;
}
}
- (void) initialize {
@ -74,6 +111,7 @@
// Create game view controller.
gameViewController = [[GameViewController alloc] initWithGameWindow:self];
[((GameView*)gameViewController.view).viewSizeChanged
subscribeDelegate:[Delegate delegateWithTarget:self Method:@selector(gameViewSizeChanged)]];
@ -102,7 +140,7 @@
- (Rectangle*) calculateClientBounds {
Rectangle *bounds = [Rectangle rectangleWithCGRect:gameViewController.view.bounds];
float scale = [UIScreen mainScreen].scale;
float scale = gameViewController.view.contentScaleFactor;
bounds.width *= scale;
bounds.height *= scale;
return bounds;

View File

@ -13,6 +13,8 @@
@interface GraphicsDevice (Internal)
- (uint) createTexture;
- (void) releaseTexture:(uint)textureId;
//- (void) getData:(void*)data fromTexture2D:(Texture2D*)texture level:(int)level;
- (void) setData:(void*)data toTexture2D:(Texture2D*)texture SourceRectangle:(Rectangle*)rect level:(int)level;

View File

@ -327,6 +327,10 @@
return textureId;
}
- (void) releaseTexture:(uint)textureId {
glDeleteTextures(1, &textureId);
}
- (void) setData:(void*)data toTexture2D:(Texture2D*)texture SourceRectangle:(Rectangle*)rect level:(int)level {
GLenum format, type;
[GraphicsDevice getFormat:&format AndType:&type ForSurfaceFormat:texture.format];

View File

@ -92,5 +92,12 @@
[graphicsDevice setData:data toTexture2D:self SourceRectangle:rect level:level];
}
- (void) dealloc
{
[graphicsDevice releaseTexture:textureId];
[super dealloc];
}
@end

View File

@ -72,6 +72,7 @@
- (void) applyChanges {
[game.window setSupportedOrientations:supportedOrientations];
[game.window beginScreenDeviceChangeWithFullscreen:isFullScreen];
[game.window endScreenDeviceChangeWithClientWidth:self.preferedBackBufferWidth clientHeight:self.preferedBackBufferHeight];
if (graphicsDevice != nil && graphicsDevice.graphicsProfile != graphicsProfile) {
// Different graphics profile requested.
@ -91,13 +92,11 @@
default:
break;
}
[game.window endScreenDeviceChange];
[deviceCreated raiseWithSender:self];
} else {
// Reset the existing device.
[deviceResetting raiseWithSender:self];
[graphicsDevice reset];
[game.window endScreenDeviceChange];
[deviceReset raiseWithSender:self];
}
}

View File

@ -147,7 +147,7 @@ static TouchPanel *instance;
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
float scale = [UIScreen mainScreen].scale;
float scale = view.contentScaleFactor;
for (UITouch *touch in touches) {
XniTouchLocation *location = [touchLocations objectForKey:touch];
if (location) {
@ -194,7 +194,7 @@ static TouchPanel *instance;
lateReleaseTouches = temp;
// Add new touches
float scale = [UIScreen mainScreen].scale;
float scale = view.contentScaleFactor;
for (UITouch *touch in addTouches) {
CGPoint position = [touch locationInView:view];
XniTouchLocation *location = [[[XniTouchLocation alloc]