since: 2012/02/27
update: 2012/02/28
reference: I touchs: Filter4Cam 學習之 Getting Raw Video Data
A. 開啓 ViewController.h 檔案, 修改如下:
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
//@add
#import <AVFoundation/AVFoundation.h>
#import <CoreMedia/CoreMedia.h>
#import <CoreVideo/CoreVideo.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreImage/CoreImage.h>
#import <ImageIO/ImageIO.h>
//@add
#import "Filter4CamHelper.h"
@interface ViewController : GLKViewController
{
//@add
// CIContext: Provides an evaluation context for rendering a CIImage object
// through Quartz 2D or OpenGL.
CIContext *coreImageContext;
// EAGLContext: Manages the state information, commands, and resources
// needed to draw using OpenGL ES.
EAGLContext *glContext;
// GLuint: 無符號四位元組整數型態,包含數值從 0 到 4,294,967,295
GLuint _renderBuffer;
// GLKView: Simplifies the effort required to create an OpenGL ES application
// by providing a default implementation of an OpenGL ES-aware view
GLKView *glView;
}
//@add
@property (strong, nonatomic) EAGLContext *glContext;
@property (strong, nonatomic) CIContext *coreImageContext;
@property (strong, nonatomic) GLKView *glView;
//@add for Render
- (void)establishRender; // establish Render
@end
----------------------------------------------------------------------------------------
B. 開啓 ViewController.m 檔案, 修改如下:
#import "ViewController.h"
@implementation ViewController
//@add
@synthesize glContext = _glContext;
@synthesize coreImageContext = _coreImageContext;
@synthesize glView = _glView;
....
#pragma mark Getter
//@add: initialize glContext
- (EAGLContext *)glContext
{
if (_glContext == nil) {
_glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
}
return _glContext;
}
//@add: initialize coreImageContext
- (CIContext *)coreImageContext
{
if (_coreImageContext == nil) {
_coreImageContext = [CIContext contextWithEAGLContext:self.glContext];
}
return _coreImageContext;
}
#pragma mark Render
//@add: establish Render
- (void)establishRender
{
// create EAGLContext: It will auto invoked by glContext "getter".
// setup: glView
self.glView = (GLKView *)self.view;
self.glView.context = self.glContext; // call glContext "getter" here.
self.glView.drawableDepthFormat = GLKViewDrawableDepthFormat24;
// setup: render buffer
glGenRenderbuffers(1, &_renderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffer);
// init Core Image context: It will auto invoked by coreImageContext "getter".
// In fact, It will invoked inner
// captureOutput:didOutputSampleBuffer:fromConnection: method.
}
- (void)viewDidUnload
{
[super viewDidUnload];
//@add
if ([EAGLContext currentContext] == self.glContext) {
[EAGLContext setCurrentContext:nil];
}
self.glContext = nil;
}
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。