roglew 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/roglew/contexts/base.rb +3 -3
- data/lib/roglew/contexts/deferred.rb +1 -1
- data/lib/roglew/contexts/immediate.rb +1 -1
- data/lib/roglew/extensions/GL_ARB_framebuffer_object/framebuffer.rb +2 -1
- data/lib/roglew/extensions/GL_ARB_framebuffer_object/renderbuffer.rb +2 -1
- data/lib/roglew/extensions/GL_ARB_framebuffer_object.rb +0 -1
- data/lib/roglew/extensions/GL_ARB_vertex_array_object/vertex_array.rb +9 -6
- data/lib/roglew/extensions/GL_ARB_vertex_array_object.rb +7 -1
- data/lib/roglew/extensions/GL_EXT_framebuffer_object/framebuffer.rb +2 -1
- data/lib/roglew/extensions/GL_EXT_framebuffer_object/renderbuffer.rb +2 -1
- data/lib/roglew/extensions/GL_EXT_framebuffer_object.rb +0 -1
- data/lib/roglew/extensions/GL_VERSION_1_5/buffer.rb +24 -0
- data/lib/roglew/extensions/GL_VERSION_1_5/buffer_context.rb +23 -0
- data/lib/roglew/extensions/GL_VERSION_1_5/query.rb +19 -0
- data/lib/roglew/extensions/GL_VERSION_1_5.rb +28 -1
- data/lib/roglew/extensions/GL_VERSION_2_0/shader.rb +3 -2
- data/lib/roglew/extensions/GL_VERSION_2_0/shader_program.rb +6 -1
- data/lib/roglew/extensions/GL_VERSION_2_0.rb +3 -5
- data/lib/roglew/gl_extension.rb +1 -0
- data/lib/roglew/texture2d.rb +2 -1
- data/lib/roglew.rb +1 -1
- metadata +5 -2
data/lib/roglew/contexts/base.rb
CHANGED
@@ -16,11 +16,11 @@ module Roglew
|
|
16
16
|
attr_reader :obj
|
17
17
|
|
18
18
|
def initialize(obj, deferred, &block)
|
19
|
-
@obj, @deferred = obj,
|
19
|
+
@obj, @deferred = obj, obj.is_deferred?(deferred)
|
20
20
|
singleton_class.send(:include, @deferred ? DeferredContext : ImmediateContext)
|
21
|
-
mod = self.class.instance_variable_get(@deferred ? :@deferred_mod :
|
21
|
+
mod = self.class.instance_variable_get(@deferred ? :@deferred_mod : :@immediate_mod)
|
22
22
|
singleton_class.send(:include, mod) if mod
|
23
|
-
run(&block) if block_given? && respond_to?(:run)
|
23
|
+
run(&block) if block_given? && respond_to?(:run, true)
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.included(c)
|
@@ -4,7 +4,8 @@ module Roglew
|
|
4
4
|
attr_reader :context, :id
|
5
5
|
|
6
6
|
def initialize(context)
|
7
|
-
@context = context
|
7
|
+
@context = context
|
8
|
+
@id = context.gen_vertex_arrays
|
8
9
|
self.class.finalize(self, @context, @id)
|
9
10
|
end
|
10
11
|
|
@@ -15,11 +16,13 @@ module Roglew
|
|
15
16
|
end)
|
16
17
|
end
|
17
18
|
|
18
|
-
def bind
|
19
|
+
def bind
|
19
20
|
@context.glBindVertexArray(@id)
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
if block_given?
|
22
|
+
yield
|
23
|
+
@context.glBindVertexArray(0)
|
24
|
+
end
|
25
|
+
self
|
23
26
|
end
|
24
27
|
end
|
25
|
-
end
|
28
|
+
end
|
@@ -7,7 +7,10 @@ end
|
|
7
7
|
module GL_ARB_vertex_array_object
|
8
8
|
module RenderContext
|
9
9
|
include Roglew::GLExtension
|
10
|
-
|
10
|
+
|
11
|
+
def create_vertex_array
|
12
|
+
Roglew::VertexArray.new(self)
|
13
|
+
end
|
11
14
|
|
12
15
|
functions [:glBindVertexArray, [ :uint ], :void],
|
13
16
|
[:glDeleteVertexArrays, [ :int, :pointer ], :void],
|
@@ -19,3 +22,6 @@ module GL_ARB_vertex_array_object
|
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
25
|
+
%w'
|
26
|
+
vertex_array
|
27
|
+
'.each { |f| require "#{File.expand_path(__FILE__)[0..-4]}/#{f}" }
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Roglew
|
2
|
+
class Buffer
|
3
|
+
include Roglew::Contextual(BufferContext)
|
4
|
+
|
5
|
+
attr_reader :context, :id
|
6
|
+
|
7
|
+
def initialize(context)
|
8
|
+
@context = context
|
9
|
+
@id = context.gen_buffers
|
10
|
+
self.class.finalize(self, @context, @id)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.finalize(obj, ctx, id)
|
14
|
+
ObjectSpace.define_finalizer(obj, proc do
|
15
|
+
puts "releasing buffer #{id}"
|
16
|
+
ctx.delete_buffers(id)
|
17
|
+
end)
|
18
|
+
end
|
19
|
+
|
20
|
+
def bind(target, deferred = nil, &block)
|
21
|
+
create_binding(deferred, target, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Roglew
|
2
|
+
class BufferContext
|
3
|
+
include Roglew::BaseContext(:buffer)
|
4
|
+
|
5
|
+
def initialize(buffer, deferred, target, &block)
|
6
|
+
@target = target
|
7
|
+
super(buffer, deferred, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def data(usage, type = nil, buffer = nil)
|
11
|
+
make_call(:buffer_data, @target, usage, type, buffer)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def bind
|
16
|
+
context.glBindBuffer(@target, buffer.id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def unbind
|
20
|
+
context.glBindBuffer(@target, 0)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Roglew
|
2
|
+
class Query
|
3
|
+
|
4
|
+
attr_reader :context, :id
|
5
|
+
|
6
|
+
def initialize(context)
|
7
|
+
@context = context
|
8
|
+
@id = context.gen_queries
|
9
|
+
self.class.finalize(self, @context, @id)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.finalize(obj, ctx, id)
|
13
|
+
ObjectSpace.define_finalizer(obj, proc do
|
14
|
+
puts "releasing query #{id}"
|
15
|
+
ctx.delete_queries(id)
|
16
|
+
end)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -56,6 +56,14 @@ module GL_VERSION_1_5
|
|
56
56
|
module RenderContext
|
57
57
|
include Roglew::GLExtension
|
58
58
|
|
59
|
+
def create_buffer
|
60
|
+
Roglew::Buffer.new(self)
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_query
|
64
|
+
Roglew::Query.new(context)
|
65
|
+
end
|
66
|
+
|
59
67
|
functions [:glBeginQuery, [ :uint, :uint ], :void],
|
60
68
|
[:glBindBuffer, [ :uint, :uint ], :void],
|
61
69
|
[:glBufferData, [ :uint, :size_t, :pointer, :uint ], :void],
|
@@ -75,5 +83,24 @@ module GL_VERSION_1_5
|
|
75
83
|
[:glIsQuery, [ :uint ], :uchar],
|
76
84
|
[:glMapBuffer, [ :uint, :uint ], :pointer],
|
77
85
|
[:glUnmapBuffer, [ :uint ], :uchar]
|
86
|
+
|
87
|
+
def_object :Buffers
|
88
|
+
def_object :Queries
|
89
|
+
|
90
|
+
def buffer_data(target, usage, type = nil, buffer = nil)
|
91
|
+
glBufferData(target, *if buffer && buffer.size > 0
|
92
|
+
p = FFI::MemoryPointer.new(type, buffer.size)
|
93
|
+
p.write_array_of_float(buffer)
|
94
|
+
[p.size, p]
|
95
|
+
else
|
96
|
+
[0, nil]
|
97
|
+
end, usage)
|
98
|
+
end
|
78
99
|
end
|
79
|
-
end
|
100
|
+
end
|
101
|
+
|
102
|
+
%w'
|
103
|
+
buffer_context
|
104
|
+
buffer
|
105
|
+
query
|
106
|
+
'.each { |f| require "#{File.expand_path(__FILE__)[0..-4]}/#{f}" }
|
@@ -3,13 +3,14 @@ module Roglew
|
|
3
3
|
attr_reader :context, :id, :type
|
4
4
|
|
5
5
|
def initialize(context, type, src = nil)
|
6
|
-
@context = context
|
6
|
+
@context = context
|
7
|
+
@id = context.glCreateShader(type)
|
7
8
|
@type = type
|
8
9
|
raise OpenGLError, "couldn't create a shader of type #{type.to_s(16)}" if @id == 0
|
9
10
|
|
10
11
|
if src
|
11
12
|
src = File.read(src) if File.file? src
|
12
|
-
|
13
|
+
compile(src)
|
13
14
|
end
|
14
15
|
|
15
16
|
self.class.finalize(self, @id, @context)
|
@@ -5,7 +5,8 @@ module Roglew
|
|
5
5
|
:shaders
|
6
6
|
|
7
7
|
def initialize(context)
|
8
|
-
@context = context
|
8
|
+
@context = context
|
9
|
+
@id = context.glCreateProgram()
|
9
10
|
end
|
10
11
|
|
11
12
|
def attach(*shaders)
|
@@ -27,6 +28,10 @@ module Roglew
|
|
27
28
|
@context.glUseProgram(@id)
|
28
29
|
end
|
29
30
|
|
31
|
+
def uniform_locations(*names)
|
32
|
+
names.map { |name| @context.glGetUniformLocation(@id, name) }
|
33
|
+
end
|
34
|
+
|
30
35
|
alias_method :link, :link_program
|
31
36
|
alias_method :use, :use_program
|
32
37
|
end
|
@@ -103,10 +103,8 @@ module GL_VERSION_2_0
|
|
103
103
|
else
|
104
104
|
raise ArgumentError, "It must be Hash or Array. Given: #{shaders.class}"
|
105
105
|
end
|
106
|
-
|
107
|
-
|
108
|
-
program.link
|
109
|
-
end
|
106
|
+
program.attach(*shaders)
|
107
|
+
program.link
|
110
108
|
program
|
111
109
|
end
|
112
110
|
|
@@ -206,7 +204,7 @@ module GL_VERSION_2_0
|
|
206
204
|
[:glVertexAttrib4ubv, [:uint, :pointer], :void],
|
207
205
|
[:glVertexAttrib4uiv, [:uint, :pointer], :void],
|
208
206
|
[:glVertexAttrib4usv, [:uint, :pointer], :void],
|
209
|
-
[:glVertexAttribPointer, [:uint, :int, :uint, :bool, :int, :
|
207
|
+
[:glVertexAttribPointer, [:uint, :int, :uint, :bool, :int, :size_t], :void]
|
210
208
|
|
211
209
|
def get_program(program, pname)
|
212
210
|
p = FFI::MemoryPointer.new(:int)
|
data/lib/roglew/gl_extension.rb
CHANGED
data/lib/roglew/texture2d.rb
CHANGED
data/lib/roglew.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roglew
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ducktape
|
@@ -477,6 +477,9 @@ files:
|
|
477
477
|
- lib/roglew/extensions/GL_VERSION_1_2.rb
|
478
478
|
- lib/roglew/extensions/GL_VERSION_1_3.rb
|
479
479
|
- lib/roglew/extensions/GL_VERSION_1_4.rb
|
480
|
+
- lib/roglew/extensions/GL_VERSION_1_5/buffer.rb
|
481
|
+
- lib/roglew/extensions/GL_VERSION_1_5/buffer_context.rb
|
482
|
+
- lib/roglew/extensions/GL_VERSION_1_5/query.rb
|
480
483
|
- lib/roglew/extensions/GL_VERSION_1_5.rb
|
481
484
|
- lib/roglew/extensions/GL_VERSION_2_0/shader.rb
|
482
485
|
- lib/roglew/extensions/GL_VERSION_2_0/shader_program.rb
|