2012年2月15日 星期三

Filter4Cam 參考: 建立描繪類別

since: 2012/02/15
update: 2012/02/17

reference: I touchs: Filter4Cam 學習之 Getting Raw Video Data

A. 建立描繪類別
    1. Xcode > File > New > New File...
        iOS > Cocoa Touch > Objective-C class > Next
        Class: Filter4CamRender
        Subclass of: GLKViewController
        > Next > Create

    2. 開啓 Filter4CamRender.h 檔案, 修改如下:
//@add
#import <GLKit/GLKit.h>

@interface Filter4CamRender : GLKViewController
{
}
@end

--------------------------------------------------------------------------------

B. 新增描繪相關變數與方法
   1. 開啓 Filter4CamRender.h 檔案, 修改如下:
//@add
#import <GLKit/GLKit.h>

@interface Filter4CamRender : 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;
   
    // GLKView: Simplifies the effort required to create an OpenGL ES application
    // by providing a default implementation of an OpenGL ES-aware view
    GLKView *glView;
   
    // GLuint: 無符號四位元組整數型態,包含數值從 0 到 4,294,967,295
    GLuint _renderBuffer;
}

//@add
@property (strong, nonatomic)CIContext *coreImageContext;
@property (strong, nonatomic)EAGLContext *glContext;
@property (strong, nonatomic)GLKView *glView;

//@add:init method
+ (id)RenderInit;

//@add:establish Render
- (void)establishRender;

@end

   2. 開啓 Filter4CamRender.m 檔案, 修改如下:
#import "Filter4CamRender.h"

@implementation Filter4CamRender

//@add
@synthesize coreImageContext = _coreImageContext;
@synthesize glContext = _glContext;
@synthesize glView = _glView;

//@add
- (id)initWithRender
{
    if (!(self = [super init])) return self;
    [self establishRender];
   
    return self;
}

//@add:establish Render
- (void)establishRender
{
    // create EAGLContext
    self.glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

    if (!self.glContext) {
        NSLog(@"Failed to create ES context");
    }
   
    // setup: glView
    self.glView = (GLKView *)self.view;
    self.glView.context = self.glContext;
    self.glView.drawableDepthFormat = GLKViewDrawableDepthFormat24;
   
    // setup: render buffer
    glGenRenderbuffers(1, &_renderBuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffer);
   
    // init: Core Image context
    self.coreImageContext = [CIContext contextWithEAGLContext:self.glContext];
}

//@add:init method
+ (id)RenderInit
{
    Filter4CamRender *render = [[Filter4CamRender alloc] initWithRender];
    return render;
}

@end

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。