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

Added a graphics device manager.

git-svn-id: http://xni.googlecode.com/svn/XNI@10 ac433895-eea3-a490-d80a-17149a75e588
This commit is contained in:
Matej Jan 2010-07-27 18:23:25 +00:00
parent e87a140ad5
commit 01f76821e6
8 changed files with 229 additions and 24 deletions

View File

@ -31,7 +31,7 @@
@synthesize orientationChanged;
- (id) handle {
return nil;//(id)gameViewController.view.layer;
return (id)gameViewController.view.layer;
}
// METHODS

View File

@ -2,13 +2,10 @@
#import <OpenGLES/ES2/gl.h>
typedef enum {
DataTypeUnsignedByte = GL_UNSIGNED_BYTE,
DataTypeByte = GL_BYTE,
DataTypeUnsignedShort = GL_UNSIGNED_SHORT,
DataTypeShort = GL_SHORT,
DataTypeFixed = GL_FIXED,
DataTypeFloat = GL_FLOAT
} DataType;
ClearOptionsDepthBuffer = GL_DEPTH_BUFFER_BIT,
ClearOptionsStencil = GL_STENCIL_BUFFER_BIT,
ClearOptionsTarget = GL_COLOR_BUFFER_BIT
} ClearOptions;
typedef enum {
CompareFunctionAlways = GL_ALWAYS,
@ -22,10 +19,20 @@ typedef enum {
} CompareFunction;
typedef enum {
ClearOptionsDepthBuffer = GL_DEPTH_BUFFER_BIT,
ClearOptionsStencil = GL_STENCIL_BUFFER_BIT,
ClearOptionsTarget = GL_COLOR_BUFFER_BIT
} ClearOptions;
DataTypeUnsignedByte = GL_UNSIGNED_BYTE,
DataTypeByte = GL_BYTE,
DataTypeUnsignedShort = GL_UNSIGNED_SHORT,
DataTypeShort = GL_SHORT,
DataTypeFixed = GL_FIXED,
DataTypeFloat = GL_FLOAT
} DataType;
typedef enum {
DepthFormatNone,
DepthFormatDepth16,
DepthFormatDepth24,
DepthFormatDepth24Stencil8
} DepthFormat;
typedef enum {
FogModeNone = 0,
@ -34,11 +41,25 @@ typedef enum {
FogModeExponentSquared = GL_EXP2
} FogMode;
typedef enum {
GraphicsProfileReach,
GraphicsProfileHiDef
} GraphicsProfile;
typedef enum {
IndexElementSizeEightBits = 1,
IndexElementSizeSixteenBits = 2,
} IndexElementSize;
typedef enum {
PrimitiveTypePointList = GL_POINTS,
PrimitiveTypeLineList = GL_LINES,
PrimitiveTypeLineStrip = GL_LINE_STRIP,
PrimitiveTypeTriangleList = GL_TRIANGLES,
PrimitiveTypeTriangleStrip = GL_TRIANGLE_STRIP,
PrimitiveTypeTriangleFan = GL_TRIANGLE_FAN
} PrimitiveType;
typedef enum {
ResourceUsageStatic = GL_STATIC_DRAW,
ResourceUsageDynamic = GL_DYNAMIC_DRAW
@ -50,6 +71,29 @@ typedef enum {
ResourceTypeVertexBuffer = GL_ARRAY_BUFFER
} ResourceType;
typedef enum {
SurfaceFormatColor,
SurfaceFormatBgr565,
SurfaceFormatBgra5551,
SurfaceFormatBgra4444,
SurfaceFormatDxt1,
SurfaceFormatDxt3,
SurfaceFormatDxt5,
SurfaceFormatNormalizedByte2,
SurfaceFormatNormalizedByte4,
SurfaceFormatRgba1010102,
SurfaceFormatRg32,
SurfaceFormatRgba64,
SurfaceFormatAlpha8,
SurfaceFormatSingle,
SurfaceFormatVector2,
SurfaceFormatVector4,
SurfaceFormatHalfSingle,
SurfaceFormatHalfVector2,
SurfaceFormatHalfVector4,
SurfaceFormatHdrBlendable
} SurfaceFormat;
typedef enum {
VertexElementFormatSingle,
VertexElementFormatVector2,
@ -78,12 +122,3 @@ typedef enum {
VertexElementUsageTextureCoordinate = GL_TEXTURE_COORD_ARRAY,
VertexElementUsagePointSize = GL_POINT_SIZE_ARRAY_OES
} VertexElementUsage;
typedef enum {
PrimitiveTypePointList = GL_POINTS,
PrimitiveTypeLineList = GL_LINES,
PrimitiveTypeLineStrip = GL_LINE_STRIP,
PrimitiveTypeTriangleList = GL_TRIANGLES,
PrimitiveTypeTriangleStrip = GL_TRIANGLE_STRIP,
PrimitiveTypeTriangleFan = GL_TRIANGLE_FAN
} PrimitiveType;

View File

@ -26,6 +26,8 @@
GLuint defaultFramebuffer, colorRenderbuffer, depthRenderbuffer;
}
@property (nonatomic, readonly) GraphicsProfile graphicsProfile;
- (id) initWithGame:(Game*) theGame;
// Presentation

View File

@ -48,6 +48,8 @@
return self;
}
@synthesize graphicsProfile;
// Presentation
- (void) reset {
CAEAGLLayer *layer = (CAEAGLLayer*)game.window.handle;
@ -75,8 +77,19 @@
}
// Render buffers
- (void) clearWithColor:(Color*)color {}
- (void) clearWithOptions:(ClearOptions)options color:(Color*)color depth:(float)depth stencil:(int)stencil {}
- (void) clearWithColor:(Color *)color {
glClearColor(color.r / 255.0, color.g / 255.0, color.b / 255.0, color.a / 255.0);
glClearDepthf(1);
glClear(ClearOptionsTarget | ClearOptionsDepthBuffer);
}
- (void) clearWithOptions:(ClearOptions)options color:(Color *)color depth:(float)depth stencil:(int)stencil {
glClearColor(color.r / 255.0, color.g / 255.0, color.b / 255.0, color.a / 255.0);
glClearDepthf(depth);
glClearStencil(stencil);
glClear(options);
}
- (EAGLContext*) createContext { return nil; }

View File

@ -0,0 +1,49 @@
//
// GraphicsDeviceManager.h
// XNI
//
// Created by Matej Jan on 27.7.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "System.h"
#import "IGraphicsDeviceManager.h"
#import "IGraphicsDeviceService.h"
#import "Retronator.Xni.Framework.classes.h"
#import "Retronator.Xni.Framework.Graphics.classes.h"
@interface GraphicsDeviceManager : NSObject <IGraphicsDeviceManager, IGraphicsDeviceService> {
GraphicsProfile graphicsProfile;
BOOL isFullScreen;
BOOL preferMultiSampling;
SurfaceFormat preferedSurfaceFormat;
int preferedBackBufferWidth;
int preferedBackBufferHeight;
DepthFormat preferedDepthStencilFormat;
DisplayOrientation supportedOrientations;
Game *game;
GraphicsDevice *graphicsDevice;
Event *deviceCreated;
Event *deviceDisposing;
Event *deviceReseting;
Event *deviceReset;
}
- (id) initWithGame:(Game*)theGame;
@property (nonatomic) GraphicsProfile graphicsProfile;
@property (nonatomic) BOOL isFullScreen;
@property (nonatomic) BOOL preferMultiSampling;
@property (nonatomic) SurfaceFormat preferedSurfaceFormat;
@property (nonatomic) int preferedBackBufferWidth;
@property (nonatomic) int preferedBackBufferHeight;
@property (nonatomic) DepthFormat preferedDepthStencilFormat;
@property (nonatomic) DisplayOrientation supportedOrientations;
- (void) toggleFullscreen;
- (void) applyChanges;
@end

View File

@ -0,0 +1,98 @@
//
// 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

View File

@ -9,7 +9,7 @@
#import "Game.h"
#import "GameTime.h"
#import "GameServiceContainer.h"
//#import "GraphicsDeviceManager.h"
#import "GraphicsDeviceManager.h"
// Game host
#import "GameHost.h"

View File

@ -37,6 +37,8 @@
B5DDE8CA11FF2AD6000DB38B /* Enums.h in Headers */ = {isa = PBXBuildFile; fileRef = B5DDE8C911FF2AD6000DB38B /* Enums.h */; };
B5DDE90911FF352E000DB38B /* Color.h in Headers */ = {isa = PBXBuildFile; fileRef = B5DDE90711FF352E000DB38B /* Color.h */; };
B5DDE90A11FF352E000DB38B /* Color.m in Sources */ = {isa = PBXBuildFile; fileRef = B5DDE90811FF352E000DB38B /* Color.m */; };
B5DDE99111FF546B000DB38B /* GraphicsDeviceManager.h in Headers */ = {isa = PBXBuildFile; fileRef = B5DDE98F11FF546B000DB38B /* GraphicsDeviceManager.h */; };
B5DDE99211FF546B000DB38B /* GraphicsDeviceManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B5DDE99011FF546B000DB38B /* GraphicsDeviceManager.m */; };
B5DE189811F8884A00BF3275 /* Delegate.h in Headers */ = {isa = PBXBuildFile; fileRef = B5DE189211F8884A00BF3275 /* Delegate.h */; };
B5DE189911F8884A00BF3275 /* Delegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B5DE189311F8884A00BF3275 /* Delegate.m */; };
B5DE189A11F8884A00BF3275 /* Event.h in Headers */ = {isa = PBXBuildFile; fileRef = B5DE189411F8884A00BF3275 /* Event.h */; };
@ -91,6 +93,8 @@
B5DDE8C911FF2AD6000DB38B /* Enums.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums.h; sourceTree = "<group>"; };
B5DDE90711FF352E000DB38B /* Color.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Color.h; sourceTree = "<group>"; };
B5DDE90811FF352E000DB38B /* Color.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Color.m; sourceTree = "<group>"; };
B5DDE98F11FF546B000DB38B /* GraphicsDeviceManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsDeviceManager.h; sourceTree = "<group>"; };
B5DDE99011FF546B000DB38B /* GraphicsDeviceManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GraphicsDeviceManager.m; sourceTree = "<group>"; };
B5DE189211F8884A00BF3275 /* Delegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Delegate.h; sourceTree = "<group>"; };
B5DE189311F8884A00BF3275 /* Delegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Delegate.m; sourceTree = "<group>"; };
B5DE189411F8884A00BF3275 /* Event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Event.h; sourceTree = "<group>"; };
@ -232,6 +236,8 @@
B5DDE7ED11FF06BB000DB38B /* GameServiceContainer.h */,
B5DDE7EE11FF06BB000DB38B /* GameServiceContainer.m */,
B5DDE82C11FF10FD000DB38B /* IGraphicsDeviceManager.h */,
B5DDE98F11FF546B000DB38B /* GraphicsDeviceManager.h */,
B5DDE99011FF546B000DB38B /* GraphicsDeviceManager.m */,
B5DDE80111FF0AE3000DB38B /* IGameComponent.h */,
B5DDE80411FF0B2D000DB38B /* IUpdatable.h */,
B5DDE80611FF0B3C000DB38B /* IDrawable.h */,
@ -299,6 +305,7 @@
B5DDE8C711FF2A23000DB38B /* HiDefGraphicsDevice.h in Headers */,
B5DDE8CA11FF2AD6000DB38B /* Enums.h in Headers */,
B5DDE90911FF352E000DB38B /* Color.h in Headers */,
B5DDE99111FF546B000DB38B /* GraphicsDeviceManager.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -366,6 +373,7 @@
B5DDE8C411FF29E8000DB38B /* ReachGraphicsDevice.m in Sources */,
B5DDE8C811FF2A23000DB38B /* HiDefGraphicsDevice.m in Sources */,
B5DDE90A11FF352E000DB38B /* Color.m in Sources */,
B5DDE99211FF546B000DB38B /* GraphicsDeviceManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};