Class: Glslkit::Reflection

Inherits:
Object
  • Object
show all
Defined in:
lib/glslkit/reflection.rb

Overview

平坦化済み(#include展開後)のGLSLをスキャンして、トップレベルの in/out/uniform宣言を抽出する。これは意図的に本格的なパーサにはしていない: コメントと、プリプロセッサディレクティブ行(#version, #line, #ifdefなど、 glslkit自身のPreprocessorが残しうるもの全般)を除去し、{}のネスト深度を 追跡して深度0の宣言以外(関数本体、ブロック本体)をスキップし、深度0の ;区切り文を1つずつ正規表現でマッチさせる。struct定義、uniform blockの メンバリスト、const/ローカル宣言は意図的にそれ以上パースしない。

各宣言はoutput_line(渡されたcodeの中での行番号)を保持する(§8.1)。 ただしこれはあくまで「渡されたcode文字列の中の行番号」であり、元ファイルの 行番号ではない。元ファイルへの変換はGlslkit::SourceMap#resolveの役目で、 ReflectionはSourceMapの存在を知らない(責務を分離するため)。

Defined Under Namespace

Classes: Attribute, Output, Uniform, UniformBlock

Constant Summary collapse

IDENT =
/[A-Za-z_]\w*/
PRECISION =
/(?:highp|mediump|lowp)\s+/
ARRAY_SUFFIX =
/(?:\s*\[\s*(\d+)\s*\])?/
LAYOUT_PREFIX =
/(?:layout\s*\(([^)]*)\)\s*)?/
UNIFORM_BLOCK_PATTERN =
/\A#{LAYOUT_PREFIX}uniform\s+(#{IDENT})\s*\{/
UNIFORM_PATTERN =
/\Auniform\s+#{PRECISION}?(#{IDENT})\s+(#{IDENT})#{ARRAY_SUFFIX}\z/
ATTRIBUTE_PATTERN =
/\A#{LAYOUT_PREFIX}in\s+#{PRECISION}?(#{IDENT})\s+(#{IDENT})#{ARRAY_SUFFIX}\z/
OUTPUT_PATTERN =
/\A#{LAYOUT_PREFIX}out\s+#{PRECISION}?(#{IDENT})\s+(#{IDENT})#{ARRAY_SUFFIX}\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ Reflection

Returns a new instance of Reflection.



38
39
40
41
42
43
44
45
46
47
# File 'lib/glslkit/reflection.rb', line 38

def initialize(code)
  @attributes = []
  @uniforms = []
  @uniform_blocks = []
  @outputs = []

  split_top_level_statements(strip_noise(code)).each do |statement, output_line|
    classify(statement.strip, output_line)
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



36
37
38
# File 'lib/glslkit/reflection.rb', line 36

def attributes
  @attributes
end

#outputsObject (readonly)

Returns the value of attribute outputs.



36
37
38
# File 'lib/glslkit/reflection.rb', line 36

def outputs
  @outputs
end

#uniform_blocksObject (readonly)

Returns the value of attribute uniform_blocks.



36
37
38
# File 'lib/glslkit/reflection.rb', line 36

def uniform_blocks
  @uniform_blocks
end

#uniformsObject (readonly)

Returns the value of attribute uniforms.



36
37
38
# File 'lib/glslkit/reflection.rb', line 36

def uniforms
  @uniforms
end