shaderize 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .DS_Store
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/shaderize ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "shaderize"))
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,423 @@
1
+
2
+ # line 1 "parser.rb.rl"
3
+ #!/usr/local/bin/ragel -o parser.rb -R -F1
4
+
5
+ module Shaderize
6
+ ShaderVariable = Struct.new(:name, :size, :type)
7
+
8
+ class Parser
9
+ def self.parse_shader_line(data)
10
+ variable_list = []
11
+
12
+ def data.[](index)
13
+ return self.slice(index).ord
14
+ end
15
+
16
+ size = 0
17
+ type = 0
18
+ name = ''
19
+
20
+
21
+ # line 22 "parser.rb"
22
+ class << self
23
+ attr_accessor :_parse_trans_keys
24
+ private :_parse_trans_keys, :_parse_trans_keys=
25
+ end
26
+ self._parse_trans_keys = [
27
+ 0, 0, 9, 118, 9, 118,
28
+ 116, 116, 116, 116, 114,
29
+ 114, 105, 105, 98, 98,
30
+ 117, 117, 116, 116, 101, 101,
31
+ 9, 32, 9, 118, 108,
32
+ 108, 111, 111, 97, 97,
33
+ 116, 116, 9, 32, 9, 122,
34
+ 9, 122, 9, 59, 110,
35
+ 110, 118, 118, 97, 97,
36
+ 114, 114, 105, 105, 97, 97,
37
+ 110, 110, 116, 116, 9,
38
+ 32, 9, 118, 110, 110,
39
+ 105, 105, 102, 102, 111, 111,
40
+ 114, 114, 109, 109, 97,
41
+ 97, 114, 114, 121, 121,
42
+ 105, 105, 110, 110, 103, 103,
43
+ 105, 105, 103, 103, 104,
44
+ 104, 112, 112, 9, 32,
45
+ 9, 118, 97, 97, 116, 116,
46
+ 50, 52, 97, 97, 109,
47
+ 109, 112, 112, 108, 108,
48
+ 101, 101, 114, 114, 50, 67,
49
+ 68, 68, 117, 117, 98,
50
+ 98, 101, 101, 101, 101,
51
+ 99, 99, 50, 52, 111, 111,
52
+ 119, 119, 97, 101, 100,
53
+ 100, 105, 105, 117, 117,
54
+ 109, 109, 9, 118, 0
55
+ ]
56
+
57
+ class << self
58
+ attr_accessor :_parse_key_spans
59
+ private :_parse_key_spans, :_parse_key_spans=
60
+ end
61
+ self._parse_key_spans = [
62
+ 0, 110, 110, 1, 1, 1, 1, 1,
63
+ 1, 1, 1, 24, 110, 1, 1, 1,
64
+ 1, 24, 114, 114, 51, 1, 1, 1,
65
+ 1, 1, 1, 1, 1, 24, 110, 1,
66
+ 1, 1, 1, 1, 1, 1, 1, 1,
67
+ 1, 1, 1, 1, 1, 1, 1, 24,
68
+ 110, 1, 1, 3, 1, 1, 1, 1,
69
+ 1, 1, 18, 1, 1, 1, 1, 1,
70
+ 1, 3, 1, 1, 5, 1, 1, 1,
71
+ 1, 110
72
+ ]
73
+
74
+ class << self
75
+ attr_accessor :_parse_index_offsets
76
+ private :_parse_index_offsets, :_parse_index_offsets=
77
+ end
78
+ self._parse_index_offsets = [
79
+ 0, 0, 111, 222, 224, 226, 228, 230,
80
+ 232, 234, 236, 238, 263, 374, 376, 378,
81
+ 380, 382, 407, 522, 637, 689, 691, 693,
82
+ 695, 697, 699, 701, 703, 705, 730, 841,
83
+ 843, 845, 847, 849, 851, 853, 855, 857,
84
+ 859, 861, 863, 865, 867, 869, 871, 873,
85
+ 898, 1009, 1011, 1013, 1017, 1019, 1021, 1023,
86
+ 1025, 1027, 1029, 1048, 1050, 1052, 1054, 1056,
87
+ 1058, 1060, 1064, 1066, 1068, 1074, 1076, 1078,
88
+ 1080, 1082
89
+ ]
90
+
91
+ class << self
92
+ attr_accessor :_parse_indicies
93
+ private :_parse_indicies, :_parse_indicies=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 1, 1, 1, 1,
131
+ 1, 1, 1, 1, 1, 1, 19, 1,
132
+ 1, 1, 1, 1, 1, 1, 1, 1,
133
+ 1, 1, 1, 1, 1, 1, 1, 1,
134
+ 1, 1, 1, 1, 1, 1, 1, 1,
135
+ 1, 1, 1, 1, 1, 1, 1, 1,
136
+ 1, 1, 1, 1, 1, 1, 1, 1,
137
+ 1, 1, 1, 1, 1, 1, 1, 1,
138
+ 1, 1, 1, 1, 1, 1, 1, 1,
139
+ 1, 1, 1, 1, 1, 1, 1, 1,
140
+ 1, 1, 1, 1, 20, 1, 21, 1,
141
+ 1, 1, 22, 23, 1, 1, 1, 1,
142
+ 1, 24, 1, 1, 25, 1, 26, 1,
143
+ 27, 1, 28, 1, 29, 1, 30, 30,
144
+ 30, 30, 30, 1, 1, 1, 1, 1,
145
+ 1, 1, 1, 1, 1, 1, 1, 1,
146
+ 1, 1, 1, 1, 1, 30, 1, 30,
147
+ 30, 30, 30, 30, 1, 1, 1, 1,
148
+ 1, 1, 1, 1, 1, 1, 1, 1,
149
+ 1, 1, 1, 1, 1, 1, 30, 1,
150
+ 1, 1, 1, 1, 1, 1, 1, 1,
151
+ 1, 1, 1, 1, 1, 1, 1, 1,
152
+ 1, 1, 1, 1, 1, 1, 1, 1,
153
+ 1, 1, 1, 1, 1, 1, 1, 31,
154
+ 31, 31, 31, 31, 31, 31, 31, 31,
155
+ 31, 31, 31, 31, 31, 31, 31, 31,
156
+ 31, 31, 31, 31, 31, 31, 31, 31,
157
+ 31, 1, 1, 1, 1, 31, 1, 31,
158
+ 31, 31, 31, 31, 31, 31, 31, 31,
159
+ 31, 31, 31, 31, 31, 31, 31, 31,
160
+ 31, 31, 31, 31, 31, 31, 31, 31,
161
+ 31, 1, 32, 32, 32, 32, 32, 1,
162
+ 1, 1, 1, 1, 1, 1, 1, 1,
163
+ 1, 1, 1, 1, 1, 1, 1, 1,
164
+ 1, 32, 1, 1, 1, 1, 1, 1,
165
+ 1, 1, 1, 1, 1, 33, 1, 1,
166
+ 1, 34, 34, 34, 34, 34, 34, 34,
167
+ 34, 34, 34, 1, 35, 1, 1, 1,
168
+ 1, 1, 34, 34, 34, 34, 34, 34,
169
+ 34, 34, 34, 34, 34, 34, 34, 34,
170
+ 34, 34, 34, 34, 34, 34, 34, 34,
171
+ 34, 34, 34, 34, 1, 1, 1, 1,
172
+ 34, 1, 34, 34, 34, 34, 34, 34,
173
+ 34, 34, 34, 34, 34, 34, 34, 34,
174
+ 34, 34, 34, 34, 34, 34, 34, 34,
175
+ 34, 34, 34, 34, 1, 36, 36, 36,
176
+ 36, 36, 1, 1, 1, 1, 1, 1,
177
+ 1, 1, 1, 1, 1, 1, 1, 1,
178
+ 1, 1, 1, 1, 36, 1, 1, 1,
179
+ 1, 1, 1, 1, 1, 1, 1, 1,
180
+ 30, 1, 1, 1, 1, 1, 1, 1,
181
+ 1, 1, 1, 1, 1, 1, 1, 37,
182
+ 1, 38, 1, 39, 1, 40, 1, 41,
183
+ 1, 42, 1, 43, 1, 44, 1, 45,
184
+ 1, 46, 46, 46, 46, 46, 1, 1,
185
+ 1, 1, 1, 1, 1, 1, 1, 1,
186
+ 1, 1, 1, 1, 1, 1, 1, 1,
187
+ 46, 1, 46, 46, 46, 46, 46, 1,
188
+ 1, 1, 1, 1, 1, 1, 1, 1,
189
+ 1, 1, 1, 1, 1, 1, 1, 1,
190
+ 1, 46, 1, 1, 1, 1, 1, 1,
191
+ 1, 1, 1, 1, 1, 1, 1, 1,
192
+ 1, 1, 1, 1, 1, 1, 1, 1,
193
+ 1, 1, 1, 1, 1, 1, 1, 1,
194
+ 1, 1, 1, 1, 1, 1, 1, 1,
195
+ 1, 1, 1, 1, 1, 1, 1, 1,
196
+ 1, 1, 1, 1, 1, 1, 1, 1,
197
+ 1, 1, 1, 1, 1, 1, 1, 1,
198
+ 1, 1, 7, 1, 1, 1, 1, 1,
199
+ 1, 1, 1, 1, 1, 1, 1, 1,
200
+ 1, 1, 1, 1, 1, 1, 9, 10,
201
+ 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1, 1, 1, 1, 1,
237
+ 1, 1, 1, 1, 1, 1, 1, 1,
238
+ 1, 1, 1, 1, 1, 1, 1, 1,
239
+ 1, 1, 1, 1, 1, 1, 1, 1,
240
+ 1, 1, 1, 1, 1, 1, 1, 1,
241
+ 1, 1, 1, 1, 1, 1, 1, 1,
242
+ 1, 1, 2, 1, 1, 1, 1, 1,
243
+ 1, 1, 3, 1, 1, 1, 1, 1,
244
+ 1, 1, 1, 1, 1, 1, 4, 5,
245
+ 1, 0
246
+ ]
247
+
248
+ class << self
249
+ attr_accessor :_parse_trans_targs
250
+ private :_parse_trans_targs, :_parse_trans_targs=
251
+ end
252
+ self._parse_trans_targs = [
253
+ 2, 0, 3, 21, 31, 37, 2, 3,
254
+ 21, 31, 37, 4, 5, 6, 7, 8,
255
+ 9, 10, 11, 12, 13, 43, 66, 68,
256
+ 52, 63, 14, 15, 16, 17, 18, 19,
257
+ 20, 18, 19, 73, 20, 73, 22, 23,
258
+ 24, 25, 26, 27, 28, 29, 30, 32,
259
+ 33, 34, 35, 36, 11, 38, 39, 40,
260
+ 41, 42, 11, 44, 45, 46, 47, 48,
261
+ 49, 50, 51, 17, 17, 17, 53, 54,
262
+ 55, 56, 57, 58, 59, 60, 61, 62,
263
+ 64, 65, 67, 69, 70, 71, 72
264
+ ]
265
+
266
+ class << self
267
+ attr_accessor :_parse_trans_actions
268
+ private :_parse_trans_actions, :_parse_trans_actions=
269
+ end
270
+ self._parse_trans_actions = [
271
+ 1, 0, 1, 1, 1, 1, 0, 0,
272
+ 0, 0, 0, 0, 0, 0, 0, 0,
273
+ 0, 0, 2, 0, 0, 0, 0, 0,
274
+ 0, 0, 0, 0, 0, 3, 0, 4,
275
+ 5, 5, 6, 5, 0, 0, 0, 0,
276
+ 0, 0, 0, 0, 0, 0, 0, 0,
277
+ 0, 0, 0, 0, 7, 0, 0, 0,
278
+ 0, 0, 8, 0, 0, 0, 0, 0,
279
+ 0, 0, 0, 9, 10, 11, 0, 0,
280
+ 0, 0, 0, 0, 0, 0, 0, 0,
281
+ 0, 0, 0, 0, 0, 0, 0
282
+ ]
283
+
284
+ class << self
285
+ attr_accessor :parse_start
286
+ end
287
+ self.parse_start = 1;
288
+ class << self
289
+ attr_accessor :parse_first_final
290
+ end
291
+ self.parse_first_final = 73;
292
+ class << self
293
+ attr_accessor :parse_error
294
+ end
295
+ self.parse_error = 0;
296
+
297
+ class << self
298
+ attr_accessor :parse_en_main
299
+ end
300
+ self.parse_en_main = 1;
301
+
302
+
303
+ # line 304 "parser.rb"
304
+ begin
305
+ p ||= 0
306
+ pe ||= data.length
307
+ cs = parse_start
308
+ end
309
+
310
+ # line 311 "parser.rb"
311
+ begin
312
+ testEof = false
313
+ _slen, _trans, _keys, _inds, _acts, _nacts = nil
314
+ _goto_level = 0
315
+ _resume = 10
316
+ _eof_trans = 15
317
+ _again = 20
318
+ _test_eof = 30
319
+ _out = 40
320
+ while true
321
+ if _goto_level <= 0
322
+ if p == pe
323
+ _goto_level = _test_eof
324
+ next
325
+ end
326
+ if cs == 0
327
+ _goto_level = _out
328
+ next
329
+ end
330
+ end
331
+ if _goto_level <= _resume
332
+ _keys = cs << 1
333
+ _inds = _parse_index_offsets[cs]
334
+ _slen = _parse_key_spans[cs]
335
+ _trans = if ( _slen > 0 &&
336
+ _parse_trans_keys[_keys] <= data[p].ord &&
337
+ data[p].ord <= _parse_trans_keys[_keys + 1]
338
+ ) then
339
+ _parse_indicies[ _inds + data[p].ord - _parse_trans_keys[_keys] ]
340
+ else
341
+ _parse_indicies[ _inds + _slen ]
342
+ end
343
+ cs = _parse_trans_targs[_trans]
344
+ if _parse_trans_actions[_trans] != 0
345
+ case _parse_trans_actions[_trans]
346
+ when 1 then
347
+ # line 22 "parser.rb.rl"
348
+ begin
349
+ size = 0; type = 0; name = ''; end
350
+ when 2 then
351
+ # line 24 "parser.rb.rl"
352
+ begin
353
+ type = :attribute; end
354
+ when 7 then
355
+ # line 25 "parser.rb.rl"
356
+ begin
357
+ type = :uniform; end
358
+ when 8 then
359
+ # line 26 "parser.rb.rl"
360
+ begin
361
+ type = :varying; end
362
+ when 3 then
363
+ # line 28 "parser.rb.rl"
364
+ begin
365
+ size = 1; end
366
+ when 9 then
367
+ # line 29 "parser.rb.rl"
368
+ begin
369
+ size = 2; end
370
+ when 10 then
371
+ # line 30 "parser.rb.rl"
372
+ begin
373
+ size = 3; end
374
+ when 11 then
375
+ # line 31 "parser.rb.rl"
376
+ begin
377
+ size = 4; end
378
+ when 6 then
379
+ # line 34 "parser.rb.rl"
380
+ begin
381
+ name += data[p].ord.chr; end
382
+ when 5 then
383
+ # line 35 "parser.rb.rl"
384
+ begin
385
+ variable_list << ShaderVariable.new( name, size, type ); end
386
+ when 4 then
387
+ # line 33 "parser.rb.rl"
388
+ begin
389
+ name = ''; end
390
+ # line 34 "parser.rb.rl"
391
+ begin
392
+ name += data[p].ord.chr; end
393
+ # line 394 "parser.rb"
394
+ end
395
+ end
396
+ end
397
+ if _goto_level <= _again
398
+ if cs == 0
399
+ _goto_level = _out
400
+ next
401
+ end
402
+ p += 1
403
+ if p != pe
404
+ _goto_level = _resume
405
+ next
406
+ end
407
+ end
408
+ if _goto_level <= _test_eof
409
+ end
410
+ if _goto_level <= _out
411
+ break
412
+ end
413
+ end
414
+ end
415
+
416
+ # line 65 "parser.rb.rl"
417
+
418
+
419
+ variable_list
420
+ end
421
+
422
+ end
423
+ end
@@ -0,0 +1,72 @@
1
+ #!/usr/local/bin/ragel -o parser.rb -R -F1
2
+
3
+ module Shaderize
4
+ ShaderVariable = Struct.new(:name, :size, :type)
5
+
6
+ class Parser
7
+
8
+ def self.parse_shader_line(data)
9
+ variable_list = []
10
+
11
+ def data.[](index)
12
+ return self.slice(index).ord
13
+ end
14
+
15
+ size = 0
16
+ type = 0
17
+ name = ''
18
+
19
+ %%{
20
+ machine parse;
21
+ write data;
22
+
23
+ action reset { size = 0; type = 0; name = ''; }
24
+
25
+ action attribute { type = :attribute; }
26
+ action uniform { type = :uniform; }
27
+ action varying { type = :varying; }
28
+
29
+ action size1 { size = 1; }
30
+ action size2 { size = 2; }
31
+ action size3 { size = 3; }
32
+ action size4 { size = 4; }
33
+
34
+ action start_identifier { name = ''; }
35
+ action build_identifier { name += fc.chr; }
36
+ action finish_identifier { variable_list << ShaderVariable.new( name, size, type ); }
37
+
38
+ invariant_qualifier = ( 'invariant' ) space+;
39
+ precision_qualifier = ( 'lowp' | 'mediump' | 'highp' ) space+;
40
+ storage_qualifier = ( 'attribute' @attribute | 'uniform' @uniform | 'varying' @varying ) space+;
41
+
42
+ type1 = ( 'float' | 'vec2' | 'vec3' | 'vec4' | 'sampler2D' | 'samplerCube' ) @size1;
43
+ type2 = ( 'mat2' ) @size2;
44
+ type3 = ( 'mat3' ) @size3;
45
+ type4 = ( 'mat4' ) @size4;
46
+ type_specifier = ( type1 | type2 | type3 | type4 ) space+;
47
+
48
+ identifier = (( alpha | '_' ) $build_identifier ( alnum | '_' )* $build_identifier) >start_identifier %finish_identifier;
49
+
50
+ declaration =
51
+ space*
52
+ invariant_qualifier?
53
+ storage_qualifier
54
+ precision_qualifier?
55
+ type_specifier
56
+ identifier
57
+ (space* ',' space* identifier)*
58
+ space*
59
+ ';'
60
+ ;
61
+
62
+ main := (declaration >reset)+;
63
+
64
+ write init;
65
+ write exec;
66
+ }%%
67
+
68
+ variable_list
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'mustache'
3
+
4
+
5
+ module Shaderize
6
+ Shader = Struct.new(:name, :attributes, :uniforms)
7
+
8
+ class Scaffold
9
+
10
+ def self.scaffold(shader_dir, output_dir)
11
+ shaders = {}
12
+ shaders_mtime = 0
13
+ Dir.glob(File.join(shader_dir, "**/*.{frag,vert}")) do |filename|
14
+ # puts "+ #{File.expand_path(filename)}"
15
+ File.open(filename) do |file|
16
+ shaders_mtime = [shaders_mtime, file.mtime.to_i].max
17
+ shader_name = File.basename(filename, File.extname(filename))
18
+ shaders[shader_name] ||= Shader.new(shader_name, [], [])
19
+ file.each_line do |line|
20
+ variables = Parser.parse_shader_line(line)
21
+ variables.each do |v|
22
+ # puts " - #{v.type} #{v.size} #{v.name}"
23
+ shaders[shader_name].attributes << v if v.type == :attribute
24
+ shaders[shader_name].uniforms << v if v.type == :uniform
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ templates = Dir.glob(File.join(output_dir, "**/*.tpl")).entries
31
+ templates_mtime = templates.map { |t| mtime(t) }
32
+
33
+ for template in templates
34
+ source_mtime = [mtime(template), shaders_mtime, mtime(__FILE__)].max
35
+ target = File.join(output_dir, File.basename(template, File.extname(template)))
36
+ target_mtime = mtime(target)
37
+ if source_mtime > target_mtime
38
+ contents = Mustache.render(File.read(template), :shaders => shaders.values)
39
+ File.open(target, "w") {|f| f.write(contents) }
40
+ puts "Shaderized: #{File.basename(target)}"
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+
47
+ private
48
+
49
+ def self.mtime(filename)
50
+ File.mtime(filename).to_i
51
+ rescue
52
+ 0
53
+ end
54
+
55
+ end
56
+ end
57
+
58
+
@@ -0,0 +1,3 @@
1
+ module Shaderize
2
+ VERSION = "0.1.1"
3
+ end
data/lib/shaderize.rb ADDED
@@ -0,0 +1,37 @@
1
+ require "rubygems"
2
+ require "mustache"
3
+
4
+ $:.unshift(File.dirname(__FILE__))
5
+
6
+ require "shaderize/version"
7
+ require "shaderize/scaffold"
8
+ require "shaderize/parser"
9
+
10
+
11
+ module Shaderize
12
+ class CLI
13
+
14
+ def self.start
15
+ error unless ARGV.length == 2
16
+
17
+ shader_dir = File.expand_path(ARGV[0])
18
+ output_dir = File.expand_path(ARGV[1])
19
+
20
+ error "Not a directory: '#{shader_dir}'" unless File.directory?(shader_dir)
21
+ error "Not a directory: '#{output_dir}'" unless File.directory?(output_dir)
22
+
23
+ Scaffold.scaffold(shader_dir, output_dir)
24
+ end
25
+
26
+ def self.error(message = nil)
27
+ puts "Shaderize v#{VERSION}"
28
+ puts "Usage: shaderize [shader_dir] [output_dir]\n"
29
+ puts message unless message.nil?
30
+ exit 1
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+
37
+ Shaderize::CLI.start
data/shaderize.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "shaderize/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "shaderize"
7
+ s.version = Shaderize::VERSION
8
+ s.authors = ["Patrick Hogan"]
9
+ s.email = ["pbhogan@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A utility to help scaffold code from OpenGL ES 2 shaders.}
12
+ s.description = %q{A utility to help scaffold code from OpenGL ES 2 shaders.}
13
+
14
+ s.rubyforge_project = "shaderize"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rake"
22
+ s.add_runtime_dependency "mustache"
23
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shaderize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Patrick Hogan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70244829776360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70244829776360
25
+ - !ruby/object:Gem::Dependency
26
+ name: mustache
27
+ requirement: &70244829775780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70244829775780
36
+ description: A utility to help scaffold code from OpenGL ES 2 shaders.
37
+ email:
38
+ - pbhogan@gmail.com
39
+ executables:
40
+ - shaderize
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - Rakefile
47
+ - bin/shaderize
48
+ - lib/.DS_Store
49
+ - lib/shaderize.rb
50
+ - lib/shaderize/parser.rb
51
+ - lib/shaderize/parser.rb.rl
52
+ - lib/shaderize/scaffold.rb
53
+ - lib/shaderize/version.rb
54
+ - shaderize.gemspec
55
+ homepage: ''
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ segments:
68
+ - 0
69
+ hash: -699704722644242517
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ segments:
77
+ - 0
78
+ hash: -699704722644242517
79
+ requirements: []
80
+ rubyforge_project: shaderize
81
+ rubygems_version: 1.8.8
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: A utility to help scaffold code from OpenGL ES 2 shaders.
85
+ test_files: []