Skip to content

Commit

Permalink
Rebase iOS framework changes on original tree to restore git history
Browse files Browse the repository at this point in the history
  • Loading branch information
tokyovigilante committed Jul 7, 2015
1 parent 14946bd commit 541b463
Show file tree
Hide file tree
Showing 6 changed files with 996 additions and 1 deletion.
19 changes: 19 additions & 0 deletions projects/xcode5/GLSLOptimizer/GLSLOptimizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// GLSLOptimiser.h
// GLSLOptimiser
//
// Created by Ryan Walklin on 2/06/2015.
//
//

#import <Foundation/Foundation.h>

//! Project version number for GLSLOptimizer.
FOUNDATION_EXPORT double GLSLOptimizerVersionNumber;

//! Project version string for GLSLOptimizer.
FOUNDATION_EXPORT const unsigned char GLSLOptimizerVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <GLSLOptimiser/PublicHeader.h>

#import "GLSLOptimizerBridge.h"
112 changes: 112 additions & 0 deletions projects/xcode5/GLSLOptimizer/GLSLOptimizerBridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//
// GLSLOptimizerBridge.h
// glsl_optimizer_lib
//
// Created by Ryan Walklin on 2/06/2015.
//
//

@class GLSLShader;

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, GLSLOptShaderType) {
GLSLOptShaderTypeVertex = 0, // kGlslOptShaderVertex
GLSLOptShaderTypeFragment // kGlslOptShaderFragment
}; // glslopt_shader_type

// Options flags for glsl_optimize
typedef NS_ENUM(NSUInteger, GLSLOptOptions) {
GLSLOptOptionsSkipProcessor = 0, //kGlslOptionSkipPreprocessor = (1<<0), // Skip preprocessing shader source. Saves some time if you know you don't need it.
GLSLOptOptionsNotFullShader // kGlslOptionNotFullShader = (1<<1), // Passed shader is not the full shader source. This makes some optimizations weaker.
}; // glslopt_options

// Optimizer target language
typedef NS_ENUM(NSUInteger, GLSLOptTarget) {
GLSLOptTargetOpenGL = 0, // kGlslTargetOpenGL = 0,
GLSLOptTargetOpenGLES20 = 1, // kGlslTargetOpenGLES20 = 1,
GLSLOptTargetOpenGLES30 = 2,// kGlslTargetOpenGLES30 = 2,
GLSLOptTargetMetal = 3// kGlslTargetMetal = 3,
}; // glslopt_target

// Type info
typedef NS_ENUM(NSUInteger, GLSLOptBasicType) {
GLSLOptBasicTypeFloat = 0, // kGlslTypeFloat = 0,
GLSLOptBasicTypeInt, // kGlslTypeInt,
GLSLOptBasicTypeBool, // kGlslTypeBool,
GLSLOptBasicTypeTex2D, // kGlslTypeTex2D,
GLSLOptBasicTypeTex3D, // kGlslTypeTex3D,
GLSLOptBasicTypeTexCube, // kGlslTypeTexCube,
GLSLOptBasicTypeOther, // kGlslTypeOther,
GLSLOptBasicTypeCount // kGlslTypeCount
}; // glslopt_basic_type

typedef NS_ENUM(NSUInteger, GLSLOptPrecision) {
GLSLOptPrecisionHigh = 0, // kGlslPrecHigh = 0,
GLSLOptPrecisionMedium, // kGlslPrecMedium,
GLSLOptPrecisionLow, // kGlslPrecLow,
GLSLOptPrecisionCount // kGlslPrecCount
}; // glslopt_precision

@interface GLSLShaderVariableDescription : NSObject

@property UInt32 index;
@property NSString *name;
@property GLSLOptBasicType type;
@property GLSLOptPrecision prec;
@property UInt32 vecSize;
@property UInt32 matSize;
@property SInt32 arraySize;
@property UInt32 location;

-(UInt32)elementCount;
-(UInt32)elementSize;
-(UInt32)rawSize;

@end

@interface GLSLShader: NSObject

-(BOOL)status;

-(NSString *)output;
-(NSString *)rawOutput;
-(NSString *)log;
-(UInt32)inputCount;
-(GLSLShaderVariableDescription *)inputDescription:(UInt32)index;

-(UInt32)uniformCount;
-(UInt32)uniformTotalSize;
-(GLSLShaderVariableDescription *)uniformDescription:(UInt32)index;

-(UInt32)textureCount;
-(GLSLShaderVariableDescription *)textureDescription:(UInt32)index;

@end

@interface GLSLOptimizer: NSObject

-(id)init:(GLSLOptTarget)target;

-(void)setMaxUnrollIterations:(UInt32)iterations;

-(GLSLShader *)optimize:(GLSLOptShaderType)shaderType shaderSource:(NSString *)shaderSource options:(NSUInteger)options;

@end



/*
int glslopt_shader_get_uniform_count (glslopt_shader* shader);
int glslopt_shader_get_uniform_total_size (glslopt_shader* shader);
void glslopt_shader_get_uniform_desc (glslopt_shader* shader, int index, const char** outName, glslopt_basic_type* outType, glslopt_precision* outPrec, int* outVecSize, int* outMatSize, int* outArraySize, int* outLocation);
int glslopt_shader_get_texture_count (glslopt_shader* shader);
void glslopt_shader_get_texture_desc (glslopt_shader* shader, int index, const char** outName, glslopt_basic_type* outType, glslopt_precision* outPrec, int* outVecSize, int* outMatSize, int* outArraySize, int* outLocation);
// Get *very* approximate shader stats:
// Number of math, texture and flow control instructions.
void glslopt_shader_get_stats (glslopt_shader* shader, int* approxMath, int* approxTex, int* approxFlow);
*/

213 changes: 213 additions & 0 deletions projects/xcode5/GLSLOptimizer/GLSLOptimizerBridge.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
//
// GLSLOptimizerBridge.m
// glsl_optimizer_lib
//
// Created by Ryan Walklin on 2/06/2015.
//
//

#import <Foundation/Foundation.h>

#import "GLSLOptimizerBridge.h"

#import "glsl_optimizer.h"

@implementation GLSLShaderVariableDescription

-(UInt32)elementCount {
return self.vecSize * self.matSize * (self.arraySize == -1 ? 1 : self.arraySize);
}

-(UInt32)elementSize {
UInt32 elementSize = 0;

switch (self.type) {
case GLSLOptBasicTypeFloat:
elementSize = sizeof(float);
break;
case GLSLOptBasicTypeInt:
elementSize = sizeof(int);
break;
case GLSLOptBasicTypeBool:
elementSize = sizeof(bool);
break;
case GLSLOptBasicTypeTex2D:
case GLSLOptBasicTypeTex3D:
case GLSLOptBasicTypeTexCube:
break;
default:
break;
}
return elementSize;
}
-(UInt32)rawSize {
return [self elementCount] * [self elementSize];
}

@end

typedef NS_ENUM(NSUInteger, GLSLShaderVariableType) {
GLSLShaderVariableTypeInput = 0,
GLSLShaderVariableTypeUniform,
GLSLShaderVariableTypeTexture
};

@interface GLSLShader () {

@private
glslopt_shader *_shader;
}

-(id)initWithShader: (glslopt_shader *)shader;

-(GLSLShaderVariableDescription *)shaderVariableDescription:(GLSLShaderVariableType)type index:(UInt32)index;

@end

@implementation GLSLShader: NSObject

-(id)initWithShader: (glslopt_shader *)shader {
self = [super init];
if (self) {
_shader = shader;
}
return self;
}

-(BOOL)status {
return glslopt_get_status(_shader) == true;
}

-(NSString *)output {
return [NSString stringWithUTF8String: glslopt_get_output(_shader)];

}

-(NSString *)rawOutput {
return [NSString stringWithUTF8String: glslopt_get_raw_output(_shader)];
}

-(NSString *)log {
return [NSString stringWithUTF8String: glslopt_get_log (_shader)];
}

-(UInt32)inputCount {
return UInt32(glslopt_shader_get_input_count(_shader));
}

-(GLSLShaderVariableDescription *)inputDescription:(UInt32)index {
NSAssert(index < self.inputCount, @"index < inputCount");
return [self shaderVariableDescription:GLSLShaderVariableTypeInput index:index];
}

-(UInt32)uniformCount {
return UInt32(glslopt_shader_get_uniform_count(_shader));
}

-(UInt32)uniformTotalSize {
return UInt32(glslopt_shader_get_uniform_total_size(_shader));
}

-(GLSLShaderVariableDescription *)uniformDescription:(UInt32)index {
NSAssert(index < self.uniformCount, @"index < inputCount");
return [self shaderVariableDescription:GLSLShaderVariableTypeUniform index:index];
}

-(UInt32)textureCount {
return UInt32(glslopt_shader_get_texture_count(_shader));
}

-(GLSLShaderVariableDescription *)textureDescription:(UInt32)index {
NSAssert(index < self.textureCount, @"index < inputCount");
return [self shaderVariableDescription:GLSLShaderVariableTypeTexture index:index];
}

-(GLSLShaderVariableDescription *)shaderVariableDescription:(GLSLShaderVariableType)type index:(UInt32)index {

const char *outName = nil;
glslopt_basic_type outType;
glslopt_precision outPrec;
int outVecSize;
int outMatSize;
int outArraySize;
int outLocation;

switch (type) {
case GLSLShaderVariableTypeInput:
glslopt_shader_get_input_desc(_shader, index, &outName, &outType, &outPrec, &outVecSize, &outMatSize, &outArraySize, &outLocation);
break;
case GLSLShaderVariableTypeUniform:
glslopt_shader_get_uniform_desc(_shader, index, &outName, &outType, &outPrec, &outVecSize, &outMatSize, &outArraySize, &outLocation);
break;
case GLSLShaderVariableTypeTexture:
glslopt_shader_get_texture_desc(_shader, index, &outName, &outType, &outPrec, &outVecSize, &outMatSize, &outArraySize, &outLocation);
break;
}

GLSLShaderVariableDescription *varDesc = [[GLSLShaderVariableDescription alloc] init];

varDesc.name = [NSString stringWithUTF8String:outName];
varDesc.type = GLSLOptBasicType(outType);
varDesc.prec = GLSLOptPrecision(outPrec);
varDesc.vecSize = SInt32(outVecSize);
varDesc.matSize = SInt32(outMatSize);
varDesc.arraySize = SInt32(outArraySize);
varDesc.location = SInt32(outLocation);

return varDesc;
}

/*
// Get *very* approximate shader stats:
// Number of math, texture and flow control instructions.
void glslopt_shader_get_stats (glslopt_shader* shader, int* approxMath, int* approxTex, int* approxFlow);
*/

- (void)dealloc
{
glslopt_shader_delete(_shader);
}

@end

@interface GLSLOptimizer () {
@private
glslopt_ctx *_ctx;
}

@end

@implementation GLSLOptimizer

-(id)init:(GLSLOptTarget)target {
self = [super init];
if (self) {
_ctx = glslopt_initialize(glslopt_target(target));
}
return self;
}

-(void)dealloc {
glslopt_cleanup(_ctx);
}

-(void)setMaxUnrollIterations:(UInt32)iterations {
glslopt_set_max_unroll_iterations(_ctx, iterations);
}

-(GLSLShader *)optimize:(GLSLOptShaderType)shaderType shaderSource:(NSString *)shaderSource options:(NSUInteger)options {
glslopt_shader* shader = glslopt_optimize(_ctx, glslopt_shader_type(shaderType), shaderSource.UTF8String, UInt32(options));

GLSLShader *glslShader = [[GLSLShader alloc] initWithShader: shader];

if ([glslShader status]) {
return glslShader;
} else {
NSLog(@"%@", [glslShader log]);
}
return nil;
}

@end


26 changes: 26 additions & 0 deletions projects/xcode5/GLSLOptimizer/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>testtoast.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
Loading

0 comments on commit 541b463

Please sign in to comment.