-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
1,431 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// FMCameraContext.h | ||
// LearnOpenGL | ||
// | ||
// Created by yfm on 2021/9/18. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <OpenGLES/ES2/gl.h> | ||
#import <OpenGLES/ES2/glext.h> | ||
#import <OpenGLES/EAGLDrawable.h> | ||
|
||
#import <CoreMedia/CoreMedia.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface FMCameraContext : NSObject | ||
|
||
// 当前使用的上下文,相机输出回调中,表示当前线程激活的上下文(重要:上下文不一致的话什么都画不出来) | ||
@property(readonly, retain, nonatomic) EAGLContext *context; | ||
// 上下文队列 | ||
@property(readonly, nonatomic) dispatch_queue_t contextQueue; | ||
// 纹理缓存对象 | ||
@property(readonly) CVOpenGLESTextureCacheRef coreVideoTextureCache; | ||
|
||
+ (FMCameraContext *)shared; | ||
+ (void)useImageProcessingContext; | ||
|
||
- (void)presentBufferForDisplay; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// FMCameraContext.m | ||
// LearnOpenGL | ||
// | ||
// Created by yfm on 2021/9/18. | ||
// | ||
|
||
#import "FMCameraContext.h" | ||
|
||
@implementation FMCameraContext | ||
|
||
@synthesize context = _context; | ||
@synthesize coreVideoTextureCache = _coreVideoTextureCache; | ||
|
||
- (instancetype)init { | ||
if(self = [super init]) { | ||
_contextQueue = dispatch_queue_create("com.sunsetlakesoftware.GPUImage.openGLESContextQueue", DISPATCH_QUEUE_SERIAL); | ||
} | ||
return self; | ||
} | ||
|
||
+ (FMCameraContext *)shared { | ||
static FMCameraContext *instance = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
instance = [[[self class] alloc] init]; | ||
}); | ||
return instance; | ||
} | ||
|
||
+ (void)useImageProcessingContext { | ||
[[FMCameraContext shared] useAsCurrentContext]; | ||
} | ||
|
||
- (void)useAsCurrentContext { | ||
EAGLContext *currentContext = [self context]; | ||
if ([EAGLContext currentContext] != currentContext) | ||
{ | ||
[EAGLContext setCurrentContext:currentContext]; | ||
} | ||
} | ||
|
||
- (EAGLContext *)context { | ||
if (_context == nil) { | ||
EAGLContext *eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; | ||
_context = eaglContext; | ||
[EAGLContext setCurrentContext:_context]; | ||
glDisable(GL_DEPTH_TEST); | ||
} | ||
|
||
return _context; | ||
} | ||
|
||
- (CVOpenGLESTextureCacheRef)coreVideoTextureCache { | ||
if (_coreVideoTextureCache == NULL) { | ||
CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, [self context], NULL, &_coreVideoTextureCache); | ||
|
||
if (err){ | ||
NSAssert(NO, @"Error at CVOpenGLESTextureCacheCreate %d", err); | ||
} | ||
} | ||
return _coreVideoTextureCache; | ||
} | ||
|
||
- (void)presentBufferForDisplay { | ||
[self.context presentRenderbuffer:GL_RENDERBUFFER]; | ||
} | ||
|
||
@end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// FMCameraLutView.h | ||
// LearnOpenGL | ||
// | ||
// Created by yfm on 2021/9/19. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface FMCameraLutView : UIView | ||
|
||
- (void)renderPixelBuffer:(CVPixelBufferRef)pixelBuffer; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Oops, something went wrong.