rubygl 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +13 -5
  2. data/.travis/push-rdoc-to-gh-pages.sh +22 -0
  3. data/.travis.yml +18 -0
  4. data/Gemfile +7 -0
  5. data/Gemfile.lock +12 -0
  6. data/LICENSE +21 -21
  7. data/README.md +40 -0
  8. data/Rakefile +98 -83
  9. data/bin/ffi_code_gen.rb +166 -166
  10. data/bin/gl_code_gen.rb +458 -458
  11. data/examples/faceted_example.rb +71 -64
  12. data/examples/instanced_example.rb +135 -127
  13. data/examples/phong_example.rb +80 -71
  14. data/ext/windows/RubyGL.so +0 -0
  15. data/lib/rubygl/event.rb +64 -0
  16. data/lib/{RubyGL → rubygl}/geometry.rb +216 -211
  17. data/lib/{RubyGL → rubygl}/math.rb +300 -300
  18. data/lib/{RubyGL → rubygl}/memory.rb +125 -121
  19. data/lib/rubygl/native/all_enums.rb +641 -0
  20. data/lib/{RubyGL/Native → rubygl/native}/glcontext.rb +23 -47
  21. data/lib/{RubyGL/Native → rubygl/native}/include/GLContext.h +36 -36
  22. data/lib/{RubyGL/Native → rubygl/native}/include/Input.h +15 -15
  23. data/lib/{RubyGL/Native → rubygl/native}/include/Window.h +27 -27
  24. data/lib/rubygl/native/input.rb +247 -0
  25. data/lib/{RubyGL/Native → rubygl/native}/opengl.rb +2808 -2032
  26. data/lib/{RubyGL/Native → rubygl/native}/src/GLContext.c +72 -72
  27. data/lib/{RubyGL/Native → rubygl/native}/src/Input.c +25 -25
  28. data/lib/{RubyGL/Native → rubygl/native}/src/Window.c +57 -57
  29. data/lib/{RubyGL/Native → rubygl/native}/window.rb +24 -24
  30. data/lib/{RubyGL → rubygl}/setup.rb +50 -50
  31. data/lib/{RubyGL → rubygl}/shader.rb +203 -203
  32. data/lib/{RubyGL → rubygl}/util.rb +77 -77
  33. data/lib/rubygl.rb +49 -48
  34. data/{RubyGL.gemspec → rubygl.gemspec} +20 -23
  35. data/test/test_util.rb +19 -0
  36. metadata +36 -33
  37. data/lib/RubyGL/Native/input.rb +0 -13
  38. data/lib/RubyGL/callback.rb +0 -10
@@ -1,122 +1,126 @@
1
- require_relative './native/opengl'
2
-
3
- module RubyGL
4
-
5
- class VertexArray
6
- # Allocates a GPU buffer for vertex_array and transfers the data as a vertex
7
- # attribute array. This allows you to access the given data from within any
8
- # shader as long as it is bound beforehand.
9
- def initialize(vertex_array)
10
- buff_ptr = FFI::MemoryPointer.new(:uint)
11
- Native.glGenBuffers(1, buff_ptr)
12
-
13
- @buffer_id = buff_ptr.get_int(0)
14
- @buffer_elements = vertex_array.size
15
- @buffer_valid = true
16
-
17
- if @buffer_id <= 0 then
18
- raise "Could Not Allocate A GPU Buffer For The VertexArray Object"
19
- end
20
-
21
- Native.glBindBuffer(Native::GL_ARRAY_BUFFER, @buffer_id)
22
-
23
- vertex_data = FFI::MemoryPointer.new(:float, vertex_array.size)
24
- vertex_data.write_array_of_float(vertex_array)
25
-
26
- Native.glBufferData(Native::GL_ARRAY_BUFFER, vertex_data.size, vertex_data, Native::GL_STATIC_DRAW)
27
-
28
- Native.glBindBuffer(Native::GL_ARRAY_BUFFER, 0)
29
- end
30
-
31
- def draw(components)
32
- raise "Call To VertexArray#draw On Invalid Object" unless @buffer_valid
33
-
34
- Native.glDrawArrays(Native::GL_TRIANGLES, 0, @buffer_elements / components)
35
- end
36
-
37
- def draw_instanced(components, iterations)
38
- raise "Call To VertexArray#draw_instanced On Invalid Object" unless @buffer_valid
39
-
40
- Native.glDrawArraysInstanced(Native::GL_TRIANGLES, 0, @buffer_elements / components, iterations)
41
- end
42
-
43
- def vertex_attrib_div(location, instances_per_change)
44
- raise "Call To VertexArray#vertex_attrib_div On Invalid Object" unless @buffer_valid
45
-
46
- Native.glVertexAttribDivisor(location, instances_per_change)
47
- end
48
-
49
- # Binds the VertexArray to the attribute at location within a shader.
50
- def vertex_attrib_ptr(location, components)
51
- raise "Call To VertexArray#vertex_attrib_ptr On Invalid Object" unless @buffer_valid
52
-
53
- # TODO: Move This To Constructor In The Future
54
- Native.glEnableVertexAttribArray(location)
55
-
56
- Native.glBindBuffer(Native::GL_ARRAY_BUFFER, @buffer_id)
57
-
58
- Native.glVertexAttribPointer(location, components, Native::GL_FLOAT, Native::GL_FALSE, 0, FFI::MemoryPointer::NULL)
59
-
60
- Native.glBindBuffer(Native::GL_ARRAY_BUFFER, 0)
61
- end
62
-
63
- # This frees the currently allocated GPU buffer for this VertexArray and
64
- # invalidates this VertexArray object. Any calls to this object after calling
65
- # this method will throw a runtime error.
66
- def release()
67
- buff_ptr = FFI::MemoryPointer.new(:uint)
68
- buff_ptr.write_uint(@buffer_id)
69
-
70
- Native.glDeleteBuffers(1, buff_ptr)
71
-
72
- @buffer_valid = false
73
- end
74
- end
75
-
76
- class IndexArray
77
- def initialize(index_array)
78
- buff_ptr = FFI::MemoryPointer.new(:pointer)
79
- Native.glGenBuffers(1, buff_ptr)
80
-
81
- @buffer_id = buff_ptr.get_int(0)
82
- @buffer_elements = index_array.size
83
- @buffer_valid = true
84
-
85
- if @buffer_id <= 0 then
86
- raise "Could Not Allocate A GPU Buffer For The IndexArray Object"
87
- end
88
-
89
- Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, @buffer_id)
90
-
91
- index_data = FFI::MemoryPointer.new(:uint, index_array.size)
92
- index_data.write_array_of_uint(index_array)
93
-
94
- Native.glBufferData(Native::GL_ELEMENT_ARRAY_BUFFER, index_data.size, index_data, Native::GL_STATIC_DRAW)
95
-
96
- Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, 0)
97
- end
98
-
99
- def draw(components)
100
- raise "Call To IndexArray#draw On Frozen Object" unless @buffer_valid
101
-
102
- Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, @buffer_id)
103
-
104
- Native.glDrawElements(Native::GL_TRIANGLES, @buffer_elements, Native::GL_UNSIGNED_INT, FFI::MemoryPointer::NULL)
105
-
106
- Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, 0)
107
- end
108
-
109
- # This frees the currently allocated GPU buffer for this IndexArray and
110
- # invalidates this IndexArray object. Any calls to this object after calling
111
- # this method will throw a runtime error.
112
- def release()
113
- buff_ptr = FFI::MemoryPointer.new(:uint)
114
- buff_ptr.put_int(@buffer_id)
115
-
116
- Native.glDeleteBuffers(1, buff_ptr)
117
-
118
- @buffer_valid = false
119
- end
120
- end
121
-
1
+ require_relative './native/opengl'
2
+
3
+ module RubyGL
4
+
5
+ class VertexArray
6
+ # Allocates a GPU buffer for vertex_array and transfers the data as a vertex
7
+ # attribute array. This allows you to access the given data from within any
8
+ # shader as long as it is bound beforehand.
9
+ def initialize(vertex_array)
10
+ buff_ptr = FFI::MemoryPointer.new(:uint)
11
+ Native.glGenBuffers(1, buff_ptr)
12
+
13
+ @buffer_id = buff_ptr.get_int(0)
14
+ @buffer_elements = vertex_array.size
15
+ @buffer_valid = true
16
+
17
+ if @buffer_id <= 0 then
18
+ raise "Could Not Allocate A GPU Buffer For The VertexArray Object"
19
+ end
20
+
21
+ Native.glBindBuffer(Native::GL_ARRAY_BUFFER, @buffer_id)
22
+
23
+ vertex_data = FFI::MemoryPointer.new(:float, vertex_array.size)
24
+ vertex_data.write_array_of_float(vertex_array)
25
+
26
+ Native.glBufferData(Native::GL_ARRAY_BUFFER, vertex_data.size, vertex_data, Native::GL_STATIC_DRAW)
27
+
28
+ Native.glBindBuffer(Native::GL_ARRAY_BUFFER, 0)
29
+ end
30
+
31
+ def draw(components)
32
+ raise "Call To VertexArray#draw On Invalid Object" unless @buffer_valid
33
+
34
+ Native.glDrawArrays(Native::GL_TRIANGLES, 0, @buffer_elements / components)
35
+ end
36
+
37
+ def draw_instanced(components, iterations)
38
+ raise "Call To VertexArray#draw_instanced On Invalid Object" unless @buffer_valid
39
+
40
+ Native.glDrawArraysInstanced(Native::GL_TRIANGLES, 0, @buffer_elements / components, iterations)
41
+ end
42
+
43
+ def vertex_attrib_div(location, instances_per_change)
44
+ raise "Call To VertexArray#vertex_attrib_div On Invalid Object" unless @buffer_valid
45
+
46
+ Native.glVertexAttribDivisor(location, instances_per_change)
47
+ end
48
+
49
+ # Binds the VertexArray to the attribute at location within a shader.
50
+ def vertex_attrib_ptr(location, components)
51
+ raise "Call To VertexArray#vertex_attrib_ptr On Invalid Object" unless @buffer_valid
52
+
53
+ # TODO: Move This To Constructor In The Future
54
+ Native.glEnableVertexAttribArray(location)
55
+
56
+ Native.glBindBuffer(Native::GL_ARRAY_BUFFER, @buffer_id)
57
+
58
+ Native.glVertexAttribPointer(location, components, Native::GL_FLOAT, Native::GL_FALSE, 0, FFI::MemoryPointer::NULL)
59
+
60
+ Native.glBindBuffer(Native::GL_ARRAY_BUFFER, 0)
61
+ end
62
+
63
+ # This frees the currently allocated GPU buffer for this VertexArray and
64
+ # invalidates this VertexArray object. Any calls to this object after calling
65
+ # this method will throw a runtime error.
66
+ def release()
67
+ raise "Call To VertexArray#release On Invalid Object" unless @buffer_valid
68
+
69
+ buff_ptr = FFI::MemoryPointer.new(:uint)
70
+ buff_ptr.write_uint(@buffer_id)
71
+
72
+ Native.glDeleteBuffers(1, buff_ptr)
73
+
74
+ @buffer_valid = false
75
+ end
76
+ end
77
+
78
+ class IndexArray
79
+ def initialize(index_array)
80
+ buff_ptr = FFI::MemoryPointer.new(:pointer)
81
+ Native.glGenBuffers(1, buff_ptr)
82
+
83
+ @buffer_id = buff_ptr.get_int(0)
84
+ @buffer_elements = index_array.size
85
+ @buffer_valid = true
86
+
87
+ if @buffer_id <= 0 then
88
+ raise "Could Not Allocate A GPU Buffer For The IndexArray Object"
89
+ end
90
+
91
+ Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, @buffer_id)
92
+
93
+ index_data = FFI::MemoryPointer.new(:uint, index_array.size)
94
+ index_data.write_array_of_uint(index_array)
95
+
96
+ Native.glBufferData(Native::GL_ELEMENT_ARRAY_BUFFER, index_data.size, index_data, Native::GL_STATIC_DRAW)
97
+
98
+ Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, 0)
99
+ end
100
+
101
+ def draw(components)
102
+ raise "Call To IndexArray#draw On Frozen Object" unless @buffer_valid
103
+
104
+ Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, @buffer_id)
105
+
106
+ Native.glDrawElements(Native::GL_TRIANGLES, @buffer_elements, Native::GL_UNSIGNED_INT, FFI::MemoryPointer::NULL)
107
+
108
+ Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, 0)
109
+ end
110
+
111
+ # This frees the currently allocated GPU buffer for this IndexArray and
112
+ # invalidates this IndexArray object. Any calls to this object after calling
113
+ # this method will throw a runtime error.
114
+ def release()
115
+ raise "Call To IndexArray#release On Invalid Object" unless @buffer_valid
116
+
117
+ buff_ptr = FFI::MemoryPointer.new(:uint)
118
+ buff_ptr.write_uint(@buffer_id)
119
+
120
+ Native.glDeleteBuffers(1, buff_ptr)
121
+
122
+ @buffer_valid = false
123
+ end
124
+ end
125
+
122
126
  end