Skip to content

Commit 541b463

Browse files
Rebase iOS framework changes on original tree to restore git history
1 parent 14946bd commit 541b463

File tree

6 files changed

+996
-1
lines changed

6 files changed

+996
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// GLSLOptimiser.h
3+
// GLSLOptimiser
4+
//
5+
// Created by Ryan Walklin on 2/06/2015.
6+
//
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
//! Project version number for GLSLOptimizer.
12+
FOUNDATION_EXPORT double GLSLOptimizerVersionNumber;
13+
14+
//! Project version string for GLSLOptimizer.
15+
FOUNDATION_EXPORT const unsigned char GLSLOptimizerVersionString[];
16+
17+
// In this header, you should import all the public headers of your framework using statements like #import <GLSLOptimiser/PublicHeader.h>
18+
19+
#import "GLSLOptimizerBridge.h"
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//
2+
// GLSLOptimizerBridge.h
3+
// glsl_optimizer_lib
4+
//
5+
// Created by Ryan Walklin on 2/06/2015.
6+
//
7+
//
8+
9+
@class GLSLShader;
10+
11+
#import <Foundation/Foundation.h>
12+
13+
typedef NS_ENUM(NSUInteger, GLSLOptShaderType) {
14+
GLSLOptShaderTypeVertex = 0, // kGlslOptShaderVertex
15+
GLSLOptShaderTypeFragment // kGlslOptShaderFragment
16+
}; // glslopt_shader_type
17+
18+
// Options flags for glsl_optimize
19+
typedef NS_ENUM(NSUInteger, GLSLOptOptions) {
20+
GLSLOptOptionsSkipProcessor = 0, //kGlslOptionSkipPreprocessor = (1<<0), // Skip preprocessing shader source. Saves some time if you know you don't need it.
21+
GLSLOptOptionsNotFullShader // kGlslOptionNotFullShader = (1<<1), // Passed shader is not the full shader source. This makes some optimizations weaker.
22+
}; // glslopt_options
23+
24+
// Optimizer target language
25+
typedef NS_ENUM(NSUInteger, GLSLOptTarget) {
26+
GLSLOptTargetOpenGL = 0, // kGlslTargetOpenGL = 0,
27+
GLSLOptTargetOpenGLES20 = 1, // kGlslTargetOpenGLES20 = 1,
28+
GLSLOptTargetOpenGLES30 = 2,// kGlslTargetOpenGLES30 = 2,
29+
GLSLOptTargetMetal = 3// kGlslTargetMetal = 3,
30+
}; // glslopt_target
31+
32+
// Type info
33+
typedef NS_ENUM(NSUInteger, GLSLOptBasicType) {
34+
GLSLOptBasicTypeFloat = 0, // kGlslTypeFloat = 0,
35+
GLSLOptBasicTypeInt, // kGlslTypeInt,
36+
GLSLOptBasicTypeBool, // kGlslTypeBool,
37+
GLSLOptBasicTypeTex2D, // kGlslTypeTex2D,
38+
GLSLOptBasicTypeTex3D, // kGlslTypeTex3D,
39+
GLSLOptBasicTypeTexCube, // kGlslTypeTexCube,
40+
GLSLOptBasicTypeOther, // kGlslTypeOther,
41+
GLSLOptBasicTypeCount // kGlslTypeCount
42+
}; // glslopt_basic_type
43+
44+
typedef NS_ENUM(NSUInteger, GLSLOptPrecision) {
45+
GLSLOptPrecisionHigh = 0, // kGlslPrecHigh = 0,
46+
GLSLOptPrecisionMedium, // kGlslPrecMedium,
47+
GLSLOptPrecisionLow, // kGlslPrecLow,
48+
GLSLOptPrecisionCount // kGlslPrecCount
49+
}; // glslopt_precision
50+
51+
@interface GLSLShaderVariableDescription : NSObject
52+
53+
@property UInt32 index;
54+
@property NSString *name;
55+
@property GLSLOptBasicType type;
56+
@property GLSLOptPrecision prec;
57+
@property UInt32 vecSize;
58+
@property UInt32 matSize;
59+
@property SInt32 arraySize;
60+
@property UInt32 location;
61+
62+
-(UInt32)elementCount;
63+
-(UInt32)elementSize;
64+
-(UInt32)rawSize;
65+
66+
@end
67+
68+
@interface GLSLShader: NSObject
69+
70+
-(BOOL)status;
71+
72+
-(NSString *)output;
73+
-(NSString *)rawOutput;
74+
-(NSString *)log;
75+
-(UInt32)inputCount;
76+
-(GLSLShaderVariableDescription *)inputDescription:(UInt32)index;
77+
78+
-(UInt32)uniformCount;
79+
-(UInt32)uniformTotalSize;
80+
-(GLSLShaderVariableDescription *)uniformDescription:(UInt32)index;
81+
82+
-(UInt32)textureCount;
83+
-(GLSLShaderVariableDescription *)textureDescription:(UInt32)index;
84+
85+
@end
86+
87+
@interface GLSLOptimizer: NSObject
88+
89+
-(id)init:(GLSLOptTarget)target;
90+
91+
-(void)setMaxUnrollIterations:(UInt32)iterations;
92+
93+
-(GLSLShader *)optimize:(GLSLOptShaderType)shaderType shaderSource:(NSString *)shaderSource options:(NSUInteger)options;
94+
95+
@end
96+
97+
98+
99+
/*
100+
101+
int glslopt_shader_get_uniform_count (glslopt_shader* shader);
102+
int glslopt_shader_get_uniform_total_size (glslopt_shader* shader);
103+
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);
104+
int glslopt_shader_get_texture_count (glslopt_shader* shader);
105+
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);
106+
107+
// Get *very* approximate shader stats:
108+
// Number of math, texture and flow control instructions.
109+
void glslopt_shader_get_stats (glslopt_shader* shader, int* approxMath, int* approxTex, int* approxFlow);
110+
111+
*/
112+
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
//
2+
// GLSLOptimizerBridge.m
3+
// glsl_optimizer_lib
4+
//
5+
// Created by Ryan Walklin on 2/06/2015.
6+
//
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
#import "GLSLOptimizerBridge.h"
12+
13+
#import "glsl_optimizer.h"
14+
15+
@implementation GLSLShaderVariableDescription
16+
17+
-(UInt32)elementCount {
18+
return self.vecSize * self.matSize * (self.arraySize == -1 ? 1 : self.arraySize);
19+
}
20+
21+
-(UInt32)elementSize {
22+
UInt32 elementSize = 0;
23+
24+
switch (self.type) {
25+
case GLSLOptBasicTypeFloat:
26+
elementSize = sizeof(float);
27+
break;
28+
case GLSLOptBasicTypeInt:
29+
elementSize = sizeof(int);
30+
break;
31+
case GLSLOptBasicTypeBool:
32+
elementSize = sizeof(bool);
33+
break;
34+
case GLSLOptBasicTypeTex2D:
35+
case GLSLOptBasicTypeTex3D:
36+
case GLSLOptBasicTypeTexCube:
37+
break;
38+
default:
39+
break;
40+
}
41+
return elementSize;
42+
}
43+
-(UInt32)rawSize {
44+
return [self elementCount] * [self elementSize];
45+
}
46+
47+
@end
48+
49+
typedef NS_ENUM(NSUInteger, GLSLShaderVariableType) {
50+
GLSLShaderVariableTypeInput = 0,
51+
GLSLShaderVariableTypeUniform,
52+
GLSLShaderVariableTypeTexture
53+
};
54+
55+
@interface GLSLShader () {
56+
57+
@private
58+
glslopt_shader *_shader;
59+
}
60+
61+
-(id)initWithShader: (glslopt_shader *)shader;
62+
63+
-(GLSLShaderVariableDescription *)shaderVariableDescription:(GLSLShaderVariableType)type index:(UInt32)index;
64+
65+
@end
66+
67+
@implementation GLSLShader: NSObject
68+
69+
-(id)initWithShader: (glslopt_shader *)shader {
70+
self = [super init];
71+
if (self) {
72+
_shader = shader;
73+
}
74+
return self;
75+
}
76+
77+
-(BOOL)status {
78+
return glslopt_get_status(_shader) == true;
79+
}
80+
81+
-(NSString *)output {
82+
return [NSString stringWithUTF8String: glslopt_get_output(_shader)];
83+
84+
}
85+
86+
-(NSString *)rawOutput {
87+
return [NSString stringWithUTF8String: glslopt_get_raw_output(_shader)];
88+
}
89+
90+
-(NSString *)log {
91+
return [NSString stringWithUTF8String: glslopt_get_log (_shader)];
92+
}
93+
94+
-(UInt32)inputCount {
95+
return UInt32(glslopt_shader_get_input_count(_shader));
96+
}
97+
98+
-(GLSLShaderVariableDescription *)inputDescription:(UInt32)index {
99+
NSAssert(index < self.inputCount, @"index < inputCount");
100+
return [self shaderVariableDescription:GLSLShaderVariableTypeInput index:index];
101+
}
102+
103+
-(UInt32)uniformCount {
104+
return UInt32(glslopt_shader_get_uniform_count(_shader));
105+
}
106+
107+
-(UInt32)uniformTotalSize {
108+
return UInt32(glslopt_shader_get_uniform_total_size(_shader));
109+
}
110+
111+
-(GLSLShaderVariableDescription *)uniformDescription:(UInt32)index {
112+
NSAssert(index < self.uniformCount, @"index < inputCount");
113+
return [self shaderVariableDescription:GLSLShaderVariableTypeUniform index:index];
114+
}
115+
116+
-(UInt32)textureCount {
117+
return UInt32(glslopt_shader_get_texture_count(_shader));
118+
}
119+
120+
-(GLSLShaderVariableDescription *)textureDescription:(UInt32)index {
121+
NSAssert(index < self.textureCount, @"index < inputCount");
122+
return [self shaderVariableDescription:GLSLShaderVariableTypeTexture index:index];
123+
}
124+
125+
-(GLSLShaderVariableDescription *)shaderVariableDescription:(GLSLShaderVariableType)type index:(UInt32)index {
126+
127+
const char *outName = nil;
128+
glslopt_basic_type outType;
129+
glslopt_precision outPrec;
130+
int outVecSize;
131+
int outMatSize;
132+
int outArraySize;
133+
int outLocation;
134+
135+
switch (type) {
136+
case GLSLShaderVariableTypeInput:
137+
glslopt_shader_get_input_desc(_shader, index, &outName, &outType, &outPrec, &outVecSize, &outMatSize, &outArraySize, &outLocation);
138+
break;
139+
case GLSLShaderVariableTypeUniform:
140+
glslopt_shader_get_uniform_desc(_shader, index, &outName, &outType, &outPrec, &outVecSize, &outMatSize, &outArraySize, &outLocation);
141+
break;
142+
case GLSLShaderVariableTypeTexture:
143+
glslopt_shader_get_texture_desc(_shader, index, &outName, &outType, &outPrec, &outVecSize, &outMatSize, &outArraySize, &outLocation);
144+
break;
145+
}
146+
147+
GLSLShaderVariableDescription *varDesc = [[GLSLShaderVariableDescription alloc] init];
148+
149+
varDesc.name = [NSString stringWithUTF8String:outName];
150+
varDesc.type = GLSLOptBasicType(outType);
151+
varDesc.prec = GLSLOptPrecision(outPrec);
152+
varDesc.vecSize = SInt32(outVecSize);
153+
varDesc.matSize = SInt32(outMatSize);
154+
varDesc.arraySize = SInt32(outArraySize);
155+
varDesc.location = SInt32(outLocation);
156+
157+
return varDesc;
158+
}
159+
160+
/*
161+
// Get *very* approximate shader stats:
162+
// Number of math, texture and flow control instructions.
163+
void glslopt_shader_get_stats (glslopt_shader* shader, int* approxMath, int* approxTex, int* approxFlow);
164+
*/
165+
166+
- (void)dealloc
167+
{
168+
glslopt_shader_delete(_shader);
169+
}
170+
171+
@end
172+
173+
@interface GLSLOptimizer () {
174+
@private
175+
glslopt_ctx *_ctx;
176+
}
177+
178+
@end
179+
180+
@implementation GLSLOptimizer
181+
182+
-(id)init:(GLSLOptTarget)target {
183+
self = [super init];
184+
if (self) {
185+
_ctx = glslopt_initialize(glslopt_target(target));
186+
}
187+
return self;
188+
}
189+
190+
-(void)dealloc {
191+
glslopt_cleanup(_ctx);
192+
}
193+
194+
-(void)setMaxUnrollIterations:(UInt32)iterations {
195+
glslopt_set_max_unroll_iterations(_ctx, iterations);
196+
}
197+
198+
-(GLSLShader *)optimize:(GLSLOptShaderType)shaderType shaderSource:(NSString *)shaderSource options:(NSUInteger)options {
199+
glslopt_shader* shader = glslopt_optimize(_ctx, glslopt_shader_type(shaderType), shaderSource.UTF8String, UInt32(options));
200+
201+
GLSLShader *glslShader = [[GLSLShader alloc] initWithShader: shader];
202+
203+
if ([glslShader status]) {
204+
return glslShader;
205+
} else {
206+
NSLog(@"%@", [glslShader log]);
207+
}
208+
return nil;
209+
}
210+
211+
@end
212+
213+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>testtoast.$(PRODUCT_NAME:rfc1034identifier)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>FMWK</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>$(CURRENT_PROJECT_VERSION)</string>
23+
<key>NSPrincipalClass</key>
24+
<string></string>
25+
</dict>
26+
</plist>

0 commit comments

Comments
 (0)