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.
- checksums.yaml +13 -5
- data/.travis/push-rdoc-to-gh-pages.sh +22 -0
- data/.travis.yml +18 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +12 -0
- data/LICENSE +21 -21
- data/README.md +40 -0
- data/Rakefile +98 -83
- data/bin/ffi_code_gen.rb +166 -166
- data/bin/gl_code_gen.rb +458 -458
- data/examples/faceted_example.rb +71 -64
- data/examples/instanced_example.rb +135 -127
- data/examples/phong_example.rb +80 -71
- data/ext/windows/RubyGL.so +0 -0
- data/lib/rubygl/event.rb +64 -0
- data/lib/{RubyGL → rubygl}/geometry.rb +216 -211
- data/lib/{RubyGL → rubygl}/math.rb +300 -300
- data/lib/{RubyGL → rubygl}/memory.rb +125 -121
- data/lib/rubygl/native/all_enums.rb +641 -0
- data/lib/{RubyGL/Native → rubygl/native}/glcontext.rb +23 -47
- data/lib/{RubyGL/Native → rubygl/native}/include/GLContext.h +36 -36
- data/lib/{RubyGL/Native → rubygl/native}/include/Input.h +15 -15
- data/lib/{RubyGL/Native → rubygl/native}/include/Window.h +27 -27
- data/lib/rubygl/native/input.rb +247 -0
- data/lib/{RubyGL/Native → rubygl/native}/opengl.rb +2808 -2032
- data/lib/{RubyGL/Native → rubygl/native}/src/GLContext.c +72 -72
- data/lib/{RubyGL/Native → rubygl/native}/src/Input.c +25 -25
- data/lib/{RubyGL/Native → rubygl/native}/src/Window.c +57 -57
- data/lib/{RubyGL/Native → rubygl/native}/window.rb +24 -24
- data/lib/{RubyGL → rubygl}/setup.rb +50 -50
- data/lib/{RubyGL → rubygl}/shader.rb +203 -203
- data/lib/{RubyGL → rubygl}/util.rb +77 -77
- data/lib/rubygl.rb +49 -48
- data/{RubyGL.gemspec → rubygl.gemspec} +20 -23
- data/test/test_util.rb +19 -0
- metadata +36 -33
- data/lib/RubyGL/Native/input.rb +0 -13
- 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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
@
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
Native.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
Native.
|
105
|
-
|
106
|
-
Native.
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
#
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
@
|
119
|
-
|
120
|
-
|
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
|