roglew 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,11 +16,11 @@ module Roglew
16
16
  attr_reader :obj
17
17
 
18
18
  def initialize(obj, deferred, &block)
19
- @obj, @deferred = obj, @obj.is_deferred?(deferred)
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 : @immediate_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)
@@ -20,7 +20,7 @@ module Roglew
20
20
 
21
21
  def run
22
22
  return unless block_given?
23
- yield
23
+ yield self
24
24
  finished
25
25
  end
26
26
  end
@@ -12,7 +12,7 @@ module Roglew
12
12
  def run
13
13
  bind
14
14
  return unless block_given?
15
- yield
15
+ yield self
16
16
  finished
17
17
  end
18
18
  end
@@ -5,7 +5,8 @@ module Roglew
5
5
  attr_reader :context, :id
6
6
 
7
7
  def initialize(context)
8
- @context = context.bind { @id = context.gen_framebuffers }
8
+ @context = context
9
+ @id = context.gen_framebuffers
9
10
  self.class.finalize(self, @context, @id)
10
11
  end
11
12
 
@@ -5,7 +5,8 @@ module Roglew
5
5
  attr_reader :context, :id
6
6
 
7
7
  def initialize(context)
8
- @context = context.bind { @id = context.gen_renderbuffers }
8
+ @context = context
9
+ @id = context.gen_renderbuffers
9
10
  self.class.finalize(self, @context, @id)
10
11
  end
11
12
 
@@ -86,7 +86,6 @@ end
86
86
  module GL_ARB_framebuffer_object
87
87
  module RenderContext
88
88
  include Roglew::GLExtension
89
- include Roglew::GLObject
90
89
 
91
90
  functions [:glBindFramebuffer, [ :uint, :uint ], :void],
92
91
  [:glBindRenderbuffer, [ :uint, :uint ], :void],
@@ -4,7 +4,8 @@ module Roglew
4
4
  attr_reader :context, :id
5
5
 
6
6
  def initialize(context)
7
- @context = context.bind { @id = context.gen_vertex_arrays }
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(&block)
19
+ def bind
19
20
  @context.glBindVertexArray(@id)
20
- return unless block_given?
21
- yield &block
22
- @context.glBindVertexArray(0)
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
- include Roglew::GLObject
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}" }
@@ -5,7 +5,8 @@ module Roglew
5
5
  attr_reader :context, :id
6
6
 
7
7
  def initialize(context)
8
- @context = context.bind { @id = context.gen_framebuffersEXT }
8
+ @context = context
9
+ @id = context.gen_framebuffersEXT
9
10
  self.class.finalize(self, @context, @id)
10
11
  end
11
12
 
@@ -5,7 +5,8 @@ module Roglew
5
5
  attr_reader :context, :id
6
6
 
7
7
  def initialize(context)
8
- @context = context.bind { @id = context.gen_renderbuffersEXT }
8
+ @context = context
9
+ @id = context.gen_renderbuffersEXT
9
10
  self.class.finalize(self, @context, @id)
10
11
  end
11
12
 
@@ -63,7 +63,6 @@ end
63
63
  module GL_EXT_framebuffer_object
64
64
  module RenderContext
65
65
  include Roglew::GLExtension
66
- include Roglew::GLObject
67
66
 
68
67
  functions [:glBindFramebufferEXT, [ :uint, :uint ], :void],
69
68
  [:glBindRenderbufferEXT, [ :uint, :uint ], :void],
@@ -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.bind { @id = context.glCreateShader(type) }
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
- @context.bind { compile(src) }
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.bind { @id = context.glCreateProgram() }
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
- bind do
107
- program.attach(*shaders)
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, :pointer], :void]
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)
@@ -16,6 +16,7 @@ module Roglew
16
16
 
17
17
  def self.included(c)
18
18
  c.extend ClassMethods
19
+ c.extend GLObject::ClassMethods
19
20
  end
20
21
  end
21
22
  end
@@ -5,7 +5,8 @@ module Roglew
5
5
  attr_reader :context, :id
6
6
 
7
7
  def initialize(context)
8
- @context = context.bind { |c| @id = c.gen_textures }
8
+ @context = context
9
+ @id = context.gen_textures
9
10
  self.class.finalize(self, @context, @id)
10
11
  end
11
12
 
data/lib/roglew.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #Raw Glue - the Ruby OpenGL and Extensions Wrapper
2
2
 
3
3
  module Roglew
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
6
6
 
7
7
  #external dependencies
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.3
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-10 00:00:00.000000000 Z
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