forked from LaiFengiOS/LFLiveKit
-
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
chenliming
committed
Nov 8, 2016
1 parent
c12a8a7
commit e64ba9d
Showing
383 changed files
with
37,829 additions
and
3,035 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
// This is Jeff LaMarche's GLProgram OpenGL shader wrapper class from his OpenGL ES 2.0 book. | ||
// A description of this can be found at his page on the topic: | ||
// http://iphonedevelopment.blogspot.com/2010/11/opengl-es-20-for-ios-chapter-4.html | ||
|
||
|
||
#import "GLProgram.h" | ||
// START:typedefs | ||
#pragma mark Function Pointer Definitions | ||
typedef void (*GLInfoFunction)(GLuint program, GLenum pname, GLint* params); | ||
typedef void (*GLLogFunction) (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); | ||
// END:typedefs | ||
#pragma mark - | ||
#pragma mark Private Extension Method Declaration | ||
// START:extension | ||
@interface GLProgram() | ||
|
||
- (BOOL)compileShader:(GLuint *)shader | ||
type:(GLenum)type | ||
string:(NSString *)shaderString; | ||
@end | ||
// END:extension | ||
#pragma mark - | ||
|
||
@implementation GLProgram | ||
// START:init | ||
|
||
@synthesize initialized = _initialized; | ||
|
||
- (id)initWithVertexShaderString:(NSString *)vShaderString | ||
fragmentShaderString:(NSString *)fShaderString; | ||
{ | ||
if ((self = [super init])) | ||
{ | ||
_initialized = NO; | ||
|
||
attributes = [[NSMutableArray alloc] init]; | ||
uniforms = [[NSMutableArray alloc] init]; | ||
program = glCreateProgram(); | ||
|
||
if (![self compileShader:&vertShader | ||
type:GL_VERTEX_SHADER | ||
string:vShaderString]) | ||
{ | ||
NSLog(@"Failed to compile vertex shader"); | ||
} | ||
|
||
// Create and compile fragment shader | ||
if (![self compileShader:&fragShader | ||
type:GL_FRAGMENT_SHADER | ||
string:fShaderString]) | ||
{ | ||
NSLog(@"Failed to compile fragment shader"); | ||
} | ||
|
||
glAttachShader(program, vertShader); | ||
glAttachShader(program, fragShader); | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (id)initWithVertexShaderString:(NSString *)vShaderString | ||
fragmentShaderFilename:(NSString *)fShaderFilename; | ||
{ | ||
NSString *fragShaderPathname = [[NSBundle mainBundle] pathForResource:fShaderFilename ofType:@"fsh"]; | ||
NSString *fragmentShaderString = [NSString stringWithContentsOfFile:fragShaderPathname encoding:NSUTF8StringEncoding error:nil]; | ||
|
||
if ((self = [self initWithVertexShaderString:vShaderString fragmentShaderString:fragmentShaderString])) | ||
{ | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (id)initWithVertexShaderFilename:(NSString *)vShaderFilename | ||
fragmentShaderFilename:(NSString *)fShaderFilename; | ||
{ | ||
NSString *vertShaderPathname = [[NSBundle mainBundle] pathForResource:vShaderFilename ofType:@"vsh"]; | ||
NSString *vertexShaderString = [NSString stringWithContentsOfFile:vertShaderPathname encoding:NSUTF8StringEncoding error:nil]; | ||
|
||
NSString *fragShaderPathname = [[NSBundle mainBundle] pathForResource:fShaderFilename ofType:@"fsh"]; | ||
NSString *fragmentShaderString = [NSString stringWithContentsOfFile:fragShaderPathname encoding:NSUTF8StringEncoding error:nil]; | ||
|
||
if ((self = [self initWithVertexShaderString:vertexShaderString fragmentShaderString:fragmentShaderString])) | ||
{ | ||
} | ||
|
||
return self; | ||
} | ||
// END:init | ||
// START:compile | ||
- (BOOL)compileShader:(GLuint *)shader | ||
type:(GLenum)type | ||
string:(NSString *)shaderString | ||
{ | ||
// CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); | ||
|
||
GLint status; | ||
const GLchar *source; | ||
|
||
source = | ||
(GLchar *)[shaderString UTF8String]; | ||
if (!source) | ||
{ | ||
NSLog(@"Failed to load vertex shader"); | ||
return NO; | ||
} | ||
|
||
*shader = glCreateShader(type); | ||
glShaderSource(*shader, 1, &source, NULL); | ||
glCompileShader(*shader); | ||
|
||
glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); | ||
|
||
if (status != GL_TRUE) | ||
{ | ||
GLint logLength; | ||
glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength); | ||
if (logLength > 0) | ||
{ | ||
GLchar *log = (GLchar *)malloc(logLength); | ||
glGetShaderInfoLog(*shader, logLength, &logLength, log); | ||
if (shader == &vertShader) | ||
{ | ||
self.vertexShaderLog = [NSString stringWithFormat:@"%s", log]; | ||
} | ||
else | ||
{ | ||
self.fragmentShaderLog = [NSString stringWithFormat:@"%s", log]; | ||
} | ||
|
||
free(log); | ||
} | ||
} | ||
|
||
// CFAbsoluteTime linkTime = (CFAbsoluteTimeGetCurrent() - startTime); | ||
// NSLog(@"Compiled in %f ms", linkTime * 1000.0); | ||
|
||
return status == GL_TRUE; | ||
} | ||
// END:compile | ||
#pragma mark - | ||
// START:addattribute | ||
- (void)addAttribute:(NSString *)attributeName | ||
{ | ||
if (![attributes containsObject:attributeName]) | ||
{ | ||
[attributes addObject:attributeName]; | ||
glBindAttribLocation(program, | ||
(GLuint)[attributes indexOfObject:attributeName], | ||
[attributeName UTF8String]); | ||
} | ||
} | ||
// END:addattribute | ||
// START:indexmethods | ||
- (GLuint)attributeIndex:(NSString *)attributeName | ||
{ | ||
return (GLuint)[attributes indexOfObject:attributeName]; | ||
} | ||
- (GLuint)uniformIndex:(NSString *)uniformName | ||
{ | ||
return glGetUniformLocation(program, [uniformName UTF8String]); | ||
} | ||
// END:indexmethods | ||
#pragma mark - | ||
// START:link | ||
- (BOOL)link | ||
{ | ||
// CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); | ||
|
||
GLint status; | ||
|
||
glLinkProgram(program); | ||
|
||
glGetProgramiv(program, GL_LINK_STATUS, &status); | ||
if (status == GL_FALSE) | ||
return NO; | ||
|
||
if (vertShader) | ||
{ | ||
glDeleteShader(vertShader); | ||
vertShader = 0; | ||
} | ||
if (fragShader) | ||
{ | ||
glDeleteShader(fragShader); | ||
fragShader = 0; | ||
} | ||
|
||
self.initialized = YES; | ||
|
||
// CFAbsoluteTime linkTime = (CFAbsoluteTimeGetCurrent() - startTime); | ||
// NSLog(@"Linked in %f ms", linkTime * 1000.0); | ||
|
||
return YES; | ||
} | ||
// END:link | ||
// START:use | ||
- (void)use | ||
{ | ||
glUseProgram(program); | ||
} | ||
// END:use | ||
#pragma mark - | ||
|
||
- (void)validate; | ||
{ | ||
GLint logLength; | ||
|
||
glValidateProgram(program); | ||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); | ||
if (logLength > 0) | ||
{ | ||
GLchar *log = (GLchar *)malloc(logLength); | ||
glGetProgramInfoLog(program, logLength, &logLength, log); | ||
self.programLog = [NSString stringWithFormat:@"%s", log]; | ||
free(log); | ||
} | ||
} | ||
|
||
#pragma mark - | ||
// START:dealloc | ||
- (void)dealloc | ||
{ | ||
if (vertShader) | ||
glDeleteShader(vertShader); | ||
|
||
if (fragShader) | ||
glDeleteShader(fragShader); | ||
|
||
if (program) | ||
glDeleteProgram(program); | ||
|
||
} | ||
// END:dealloc | ||
@end |
File renamed without changes.
File renamed without changes.
128 changes: 128 additions & 0 deletions
128
LFLiveKit/Vendor/GPUImage/GPUImage3x3ConvolutionFilter.m
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,128 @@ | ||
#import "GPUImage3x3ConvolutionFilter.h" | ||
|
||
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE | ||
NSString *const kGPUImage3x3ConvolutionFragmentShaderString = SHADER_STRING | ||
( | ||
precision highp float; | ||
|
||
uniform sampler2D inputImageTexture; | ||
|
||
uniform mediump mat3 convolutionMatrix; | ||
|
||
varying vec2 textureCoordinate; | ||
varying vec2 leftTextureCoordinate; | ||
varying vec2 rightTextureCoordinate; | ||
|
||
varying vec2 topTextureCoordinate; | ||
varying vec2 topLeftTextureCoordinate; | ||
varying vec2 topRightTextureCoordinate; | ||
|
||
varying vec2 bottomTextureCoordinate; | ||
varying vec2 bottomLeftTextureCoordinate; | ||
varying vec2 bottomRightTextureCoordinate; | ||
|
||
void main() | ||
{ | ||
mediump vec3 bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; | ||
mediump vec3 bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb; | ||
mediump vec3 bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb; | ||
mediump vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); | ||
mediump vec3 leftColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; | ||
mediump vec3 rightColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; | ||
mediump vec3 topColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; | ||
mediump vec3 topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).rgb; | ||
mediump vec3 topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).rgb; | ||
|
||
mediump vec3 resultColor = topLeftColor * convolutionMatrix[0][0] + topColor * convolutionMatrix[0][1] + topRightColor * convolutionMatrix[0][2]; | ||
resultColor += leftColor * convolutionMatrix[1][0] + centerColor.rgb * convolutionMatrix[1][1] + rightColor * convolutionMatrix[1][2]; | ||
resultColor += bottomLeftColor * convolutionMatrix[2][0] + bottomColor * convolutionMatrix[2][1] + bottomRightColor * convolutionMatrix[2][2]; | ||
|
||
gl_FragColor = vec4(resultColor, centerColor.a); | ||
} | ||
); | ||
#else | ||
NSString *const kGPUImage3x3ConvolutionFragmentShaderString = SHADER_STRING | ||
( | ||
uniform sampler2D inputImageTexture; | ||
|
||
uniform mat3 convolutionMatrix; | ||
|
||
varying vec2 textureCoordinate; | ||
varying vec2 leftTextureCoordinate; | ||
varying vec2 rightTextureCoordinate; | ||
|
||
varying vec2 topTextureCoordinate; | ||
varying vec2 topLeftTextureCoordinate; | ||
varying vec2 topRightTextureCoordinate; | ||
|
||
varying vec2 bottomTextureCoordinate; | ||
varying vec2 bottomLeftTextureCoordinate; | ||
varying vec2 bottomRightTextureCoordinate; | ||
|
||
void main() | ||
{ | ||
vec3 bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; | ||
vec3 bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb; | ||
vec3 bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb; | ||
vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); | ||
vec3 leftColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; | ||
vec3 rightColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; | ||
vec3 topColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; | ||
vec3 topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).rgb; | ||
vec3 topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).rgb; | ||
|
||
vec3 resultColor = topLeftColor * convolutionMatrix[0][0] + topColor * convolutionMatrix[0][1] + topRightColor * convolutionMatrix[0][2]; | ||
resultColor += leftColor * convolutionMatrix[1][0] + centerColor.rgb * convolutionMatrix[1][1] + rightColor * convolutionMatrix[1][2]; | ||
resultColor += bottomLeftColor * convolutionMatrix[2][0] + bottomColor * convolutionMatrix[2][1] + bottomRightColor * convolutionMatrix[2][2]; | ||
|
||
gl_FragColor = vec4(resultColor, centerColor.a); | ||
} | ||
); | ||
#endif | ||
|
||
@implementation GPUImage3x3ConvolutionFilter | ||
|
||
@synthesize convolutionKernel = _convolutionKernel; | ||
|
||
#pragma mark - | ||
#pragma mark Initialization and teardown | ||
|
||
- (id)init; | ||
{ | ||
if (!(self = [self initWithFragmentShaderFromString:kGPUImage3x3ConvolutionFragmentShaderString])) | ||
{ | ||
return nil; | ||
} | ||
|
||
self.convolutionKernel = (GPUMatrix3x3){ | ||
{0.f, 0.f, 0.f}, | ||
{0.f, 1.f, 0.f}, | ||
{0.f, 0.f, 0.f} | ||
}; | ||
|
||
return self; | ||
} | ||
|
||
- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; | ||
{ | ||
if (!(self = [super initWithFragmentShaderFromString:fragmentShaderString])) | ||
{ | ||
return nil; | ||
} | ||
|
||
convolutionMatrixUniform = [filterProgram uniformIndex:@"convolutionMatrix"]; | ||
|
||
return self; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark Accessors | ||
|
||
- (void)setConvolutionKernel:(GPUMatrix3x3)newValue; | ||
{ | ||
_convolutionKernel = newValue; | ||
|
||
[self setMatrix3f:_convolutionKernel forUniform:convolutionMatrixUniform program:filterProgram]; | ||
} | ||
|
||
@end |
File renamed without changes.
Oops, something went wrong.