From daba96226a9421e6645ce25821d367aafa228b2b Mon Sep 17 00:00:00 2001 From: chsieh Date: Sun, 17 Apr 2011 16:24:52 -0700 Subject: [PATCH] Renaming files and updating references. --- Classes/Foundation/OSInterface/EAGLView.h | 32 ---- Classes/Foundation/OSInterface/EAGLView.m | 156 -------------------- Classes/Foundation/OSInterface/GLView.h | 32 ++++ Classes/Foundation/OSInterface/GLView.m | 156 ++++++++++++++++++++ .../OSInterface/LittlestViewController.m | 2 +- 5 files changed, 189 insertions(+), 189 deletions(-) delete mode 100644 Classes/Foundation/OSInterface/EAGLView.h delete mode 100644 Classes/Foundation/OSInterface/EAGLView.m create mode 100644 Classes/Foundation/OSInterface/GLView.h create mode 100644 Classes/Foundation/OSInterface/GLView.m diff --git a/Classes/Foundation/OSInterface/EAGLView.h b/Classes/Foundation/OSInterface/EAGLView.h deleted file mode 100644 index 0d2efa8..0000000 --- a/Classes/Foundation/OSInterface/EAGLView.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#import - -#import -#import -#import -#import - -//---------------------------------------------------------------------------------------- -// This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. -// The view content is basically an EAGL surface you render your OpenGL scene into. -// Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. -@interface GLView : UIView -{ -@private - EAGLContext* context; - - // The pixel dimensions of the CAEAGLLayer. - GLint framebufferWidth; - GLint framebufferHeight; - - // The OpenGL ES names for the framebuffer and renderbuffer used to render to this view. - GLuint defaultFramebuffer, colorRenderbuffer; -} - -@property (nonatomic, retain) EAGLContext* context; - -- (void)setFramebuffer; -- (BOOL)presentFramebuffer; - -@end diff --git a/Classes/Foundation/OSInterface/EAGLView.m b/Classes/Foundation/OSInterface/EAGLView.m deleted file mode 100644 index 3ec3e3e..0000000 --- a/Classes/Foundation/OSInterface/EAGLView.m +++ /dev/null @@ -1,156 +0,0 @@ -#import - -#import "EAGLView.h" - -//----------------------------------------------------------------------------------------------------------- -@interface GLView (PrivateMethods) -- (void)createFrameBuffer; -- (void)deleteFramebuffer; -@end - -//----------------------------------------------------------------------------------------------------------- -@implementation GLView - -@dynamic context; - -//----------------------------------------------------------------------------------------------------------- -// You must implement this method -+ (Class)layerClass -{ - return [CAEAGLLayer class]; -} - -//----------------------------------------------------------------------------------------------------------- -//The EAGL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:. -- (id)initWithCoder:(NSCoder*)coder -{ - self = [super initWithCoder:coder]; - if (self) - { - CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; - - eaglLayer.opaque = TRUE; - eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, - kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, - nil]; - } - - return self; -} - -//----------------------------------------------------------------------------------------------------------- -- (void)dealloc -{ - [self deleteFramebuffer]; - [context release]; - - [super dealloc]; -} - -//----------------------------------------------------------------------------------------------------------- -- (EAGLContext *)context -{ - return context; -} - -//----------------------------------------------------------------------------------------------------------- -- (void)setContext:(EAGLContext *)newContext -{ - if (context != newContext) - { - [self deleteFramebuffer]; - [context release]; - - context = [newContext retain]; - [EAGLContext setCurrentContext:nil]; - } -} - -//----------------------------------------------------------------------------------------------------------- -- (void)createFrameBuffer -{ - if (context && !defaultFramebuffer) - { - [EAGLContext setCurrentContext:context]; - - // Create default framebuffer object. - glGenFramebuffers(1, &defaultFramebuffer); - glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer); - - // Create color render buffer and allocate backing store. - glGenRenderbuffers(1, &colorRenderbuffer); - glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer); - [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer]; - glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth); - glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight); - - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer); - - if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) - NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER)); - } -} - -//----------------------------------------------------------------------------------------------------------- -- (void)deleteFramebuffer -{ - if (context) - { - [EAGLContext setCurrentContext:context]; - - if (defaultFramebuffer) - { - glDeleteFramebuffers(1, &defaultFramebuffer); - defaultFramebuffer = 0; - } - - if (colorRenderbuffer) - { - glDeleteRenderbuffers(1, &colorRenderbuffer); - colorRenderbuffer = 0; - } - } -} - -//----------------------------------------------------------------------------------------------------------- -- (void)setFramebuffer -{ - if (context) - { - [EAGLContext setCurrentContext:context]; - - if (!defaultFramebuffer) - [self createFrameBuffer]; - - glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer); - - glViewport(0, 0, framebufferWidth, framebufferHeight); - } -} - -//----------------------------------------------------------------------------------------------------------- -- (BOOL)presentFramebuffer -{ - BOOL success = FALSE; - - if (context) - { - [EAGLContext setCurrentContext:context]; - - glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer); - - success = [context presentRenderbuffer:GL_RENDERBUFFER]; - } - - return success; -} - -//----------------------------------------------------------------------------------------------------------- -- (void)layoutSubviews -{ - // The framebuffer will be re-created at the beginning of the next setFramebuffer method call. - [self deleteFramebuffer]; -} - -@end diff --git a/Classes/Foundation/OSInterface/GLView.h b/Classes/Foundation/OSInterface/GLView.h new file mode 100644 index 0000000..0d2efa8 --- /dev/null +++ b/Classes/Foundation/OSInterface/GLView.h @@ -0,0 +1,32 @@ +#pragma once + +#import + +#import +#import +#import +#import + +//---------------------------------------------------------------------------------------- +// This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. +// The view content is basically an EAGL surface you render your OpenGL scene into. +// Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. +@interface GLView : UIView +{ +@private + EAGLContext* context; + + // The pixel dimensions of the CAEAGLLayer. + GLint framebufferWidth; + GLint framebufferHeight; + + // The OpenGL ES names for the framebuffer and renderbuffer used to render to this view. + GLuint defaultFramebuffer, colorRenderbuffer; +} + +@property (nonatomic, retain) EAGLContext* context; + +- (void)setFramebuffer; +- (BOOL)presentFramebuffer; + +@end diff --git a/Classes/Foundation/OSInterface/GLView.m b/Classes/Foundation/OSInterface/GLView.m new file mode 100644 index 0000000..3ec3e3e --- /dev/null +++ b/Classes/Foundation/OSInterface/GLView.m @@ -0,0 +1,156 @@ +#import + +#import "EAGLView.h" + +//----------------------------------------------------------------------------------------------------------- +@interface GLView (PrivateMethods) +- (void)createFrameBuffer; +- (void)deleteFramebuffer; +@end + +//----------------------------------------------------------------------------------------------------------- +@implementation GLView + +@dynamic context; + +//----------------------------------------------------------------------------------------------------------- +// You must implement this method ++ (Class)layerClass +{ + return [CAEAGLLayer class]; +} + +//----------------------------------------------------------------------------------------------------------- +//The EAGL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:. +- (id)initWithCoder:(NSCoder*)coder +{ + self = [super initWithCoder:coder]; + if (self) + { + CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; + + eaglLayer.opaque = TRUE; + eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, + kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, + nil]; + } + + return self; +} + +//----------------------------------------------------------------------------------------------------------- +- (void)dealloc +{ + [self deleteFramebuffer]; + [context release]; + + [super dealloc]; +} + +//----------------------------------------------------------------------------------------------------------- +- (EAGLContext *)context +{ + return context; +} + +//----------------------------------------------------------------------------------------------------------- +- (void)setContext:(EAGLContext *)newContext +{ + if (context != newContext) + { + [self deleteFramebuffer]; + [context release]; + + context = [newContext retain]; + [EAGLContext setCurrentContext:nil]; + } +} + +//----------------------------------------------------------------------------------------------------------- +- (void)createFrameBuffer +{ + if (context && !defaultFramebuffer) + { + [EAGLContext setCurrentContext:context]; + + // Create default framebuffer object. + glGenFramebuffers(1, &defaultFramebuffer); + glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer); + + // Create color render buffer and allocate backing store. + glGenRenderbuffers(1, &colorRenderbuffer); + glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer); + [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer]; + glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth); + glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight); + + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer); + + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) + NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER)); + } +} + +//----------------------------------------------------------------------------------------------------------- +- (void)deleteFramebuffer +{ + if (context) + { + [EAGLContext setCurrentContext:context]; + + if (defaultFramebuffer) + { + glDeleteFramebuffers(1, &defaultFramebuffer); + defaultFramebuffer = 0; + } + + if (colorRenderbuffer) + { + glDeleteRenderbuffers(1, &colorRenderbuffer); + colorRenderbuffer = 0; + } + } +} + +//----------------------------------------------------------------------------------------------------------- +- (void)setFramebuffer +{ + if (context) + { + [EAGLContext setCurrentContext:context]; + + if (!defaultFramebuffer) + [self createFrameBuffer]; + + glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer); + + glViewport(0, 0, framebufferWidth, framebufferHeight); + } +} + +//----------------------------------------------------------------------------------------------------------- +- (BOOL)presentFramebuffer +{ + BOOL success = FALSE; + + if (context) + { + [EAGLContext setCurrentContext:context]; + + glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer); + + success = [context presentRenderbuffer:GL_RENDERBUFFER]; + } + + return success; +} + +//----------------------------------------------------------------------------------------------------------- +- (void)layoutSubviews +{ + // The framebuffer will be re-created at the beginning of the next setFramebuffer method call. + [self deleteFramebuffer]; +} + +@end diff --git a/Classes/Foundation/OSInterface/LittlestViewController.m b/Classes/Foundation/OSInterface/LittlestViewController.m index a701947..df6f580 100644 --- a/Classes/Foundation/OSInterface/LittlestViewController.m +++ b/Classes/Foundation/OSInterface/LittlestViewController.m @@ -1,7 +1,7 @@ #import #import "LittlestViewController.h" -#import "EAGLView.h" +#import "GLView.h" #import "cocos2d/cocos2d.h" -- 1.7.0.4