ashton 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -16,7 +16,7 @@ module Gosu
16
16
  if shader
17
17
  shader.enable z
18
18
  $window.gl z do
19
- glActiveTexture GL_TEXTURE0 # Let's make an assumption :)
19
+ Gl.glActiveTexture Gl::GL_TEXTURE0 # Let's make an assumption :)
20
20
  shader.color = args[6].is_a?(Color) ? args[6] : DEFAULT_DRAW_COLOR
21
21
  end
22
22
  end
@@ -42,7 +42,7 @@ module Gosu
42
42
  if shader
43
43
  shader.enable z
44
44
  $window.gl z do
45
- glActiveTexture GL_TEXTURE0 # Let's make an assumption :)
45
+ Gl.glActiveTexture GL::GL_TEXTURE0 # Let's make an assumption :)
46
46
  shader.color = args[8].is_a?(Color) ? args[8] : DEFAULT_DRAW_COLOR
47
47
  end
48
48
  end
data/lib/ashton/shader.rb CHANGED
@@ -22,7 +22,7 @@ module Ashton
22
22
  def enabled?; !!@previous_program end
23
23
 
24
24
  # Is this the currently activated shader program?
25
- def current?; glGetIntegerv(GL_CURRENT_PROGRAM) == @program end
25
+ def current?; Gl.glGetIntegerv(Gl::GL_CURRENT_PROGRAM) == @program end
26
26
 
27
27
  # Instead of passing in source code, a file-name will be loaded or use a symbol to choose a built-in shader.
28
28
  #
@@ -53,13 +53,14 @@ module Ashton
53
53
  @color = [1, 1, 1, 1]
54
54
 
55
55
  # Actually compile and link.
56
- @vertex = compile GL_VERTEX_SHADER, @vertex_source
57
- @fragment = compile GL_FRAGMENT_SHADER, @fragment_source
56
+
57
+ @vertex = compile Gl::GL_VERTEX_SHADER, @vertex_source
58
+ @fragment = compile Gl::GL_FRAGMENT_SHADER, @fragment_source
58
59
  link
59
60
 
60
61
  # In case we are using '#version 130' or higher, set out own color output.
61
62
  begin
62
- glBindFragDataLocationEXT @program, 0, "out_FragColor"
63
+ Gl.glBindFragDataLocationEXT @program, 0, "out_FragColor"
63
64
  rescue NotImplementedError
64
65
  # Might fail on an old system, but they will be fine just running GLSL 1.10 or 1.20
65
66
  end
@@ -103,11 +104,11 @@ module Ashton
103
104
  def enable(z = nil)
104
105
  $window.gl z do
105
106
  raise ShaderError, "This shader already enabled." if enabled?
106
- current_shader = glGetIntegerv GL_CURRENT_PROGRAM
107
+ current_shader = Gl.glGetIntegerv GL::GL_CURRENT_PROGRAM
107
108
  raise ShaderError, "Another shader already enabled." if current_shader > 0
108
109
 
109
110
  @previous_program = current_shader
110
- glUseProgram @program
111
+ Gl.glUseProgram @program
111
112
  end
112
113
 
113
114
  result = nil
@@ -127,7 +128,7 @@ module Ashton
127
128
  def disable(z = nil)
128
129
  $window.gl z do
129
130
  raise ShaderError, "Shader not enabled." unless enabled?
130
- glUseProgram @previous_program # Disable the shader!
131
+ Gl.glUseProgram @previous_program # Disable the shader!
131
132
  @previous_program = nil
132
133
  end
133
134
 
@@ -175,28 +176,28 @@ module Ashton
175
176
  return if location == INVALID_LOCATION # Not for end-users :)
176
177
 
177
178
  case value
178
- when true, GL_TRUE
179
- glUniform1i location, 1
179
+ when true, Gl::GL_TRUE
180
+ Gl.glUniform1i location, 1
180
181
 
181
- when false, GL_FALSE
182
- glUniform1i location, 0
182
+ when false, Gl::GL_FALSE
183
+ Gl.glUniform1i location, 0
183
184
 
184
185
  when Float
185
186
  begin
186
- glUniform1f location, value
187
+ Gl.glUniform1f location, value
187
188
  rescue
188
- glUniform1i location, value.to_i
189
+ Gl.glUniform1i location, value.to_i
189
190
  end
190
191
 
191
192
  when Integer
192
193
  begin
193
- glUniform1i location, value
194
+ Gl.glUniform1i location, value
194
195
  rescue
195
- glUniform1f location, value.to_f
196
+ Gl.glUniform1f location, value.to_f
196
197
  end
197
198
 
198
199
  when Gosu::Color
199
- glUniform4f location, *value.to_opengl
200
+ Gl.glUniform4f location, *value.to_opengl
200
201
 
201
202
  when Array
202
203
  size = value.size
@@ -207,16 +208,16 @@ module Ashton
207
208
  case value[0]
208
209
  when Float
209
210
  begin
210
- GL.send "glUniform#{size}f", location, *value.map(&:to_f)
211
+ Gl.send "glUniform#{size}f", location, *value.map(&:to_f)
211
212
  rescue
212
- GL.send "glUniform#{size}i", location, *value.map(&:to_i)
213
+ Gl.send "glUniform#{size}i", location, *value.map(&:to_i)
213
214
  end
214
215
 
215
216
  when Integer
216
217
  begin
217
- GL.send "glUniform#{size}i", location, *value.map(&:to_i)
218
+ Gl.send "glUniform#{size}i", location, *value.map(&:to_i)
218
219
  rescue
219
- GL.send "glUniform#{size}f", location, *value.map(&:to_f)
220
+ Gl.send "glUniform#{size}f", location, *value.map(&:to_f)
220
221
  end
221
222
 
222
223
  else
@@ -240,7 +241,7 @@ module Ashton
240
241
  if location
241
242
  location
242
243
  else
243
- location = glGetUniformLocation @program, name.to_s
244
+ location = Gl.glGetUniformLocation @program, name.to_s
244
245
  if options[:required] && location == INVALID_LOCATION
245
246
  raise ShaderUniformError, "No #{name.inspect} uniform specified in program"
246
247
  end
@@ -255,8 +256,8 @@ module Ashton
255
256
  if image
256
257
  info = image.gl_tex_info
257
258
 
258
- glActiveTexture GL_TEXTURE0
259
- glBindTexture GL_TEXTURE_2D, info.tex_name
259
+ Gl.glActiveTexture Gl::GL_TEXTURE0
260
+ Gl.glBindTexture Gl::GL_TEXTURE_2D, info.tex_name
260
261
  end
261
262
 
262
263
  set_uniform uniform_location("in_TextureEnabled", required: false), !!image
@@ -279,8 +280,8 @@ module Ashton
279
280
 
280
281
  needs_use = !current?
281
282
  enable if needs_use
282
- location = glGetAttribLocation @program, "in_Color"
283
- glVertexAttrib4f location, *opengl_color unless location == INVALID_LOCATION
283
+ location = Gl.glGetAttribLocation @program, "in_Color"
284
+ Gl.glVertexAttrib4f location, *opengl_color unless location == INVALID_LOCATION
284
285
  disable if needs_use
285
286
 
286
287
  @color = opengl_color
@@ -292,7 +293,7 @@ module Ashton
292
293
  if location
293
294
  location
294
295
  else
295
- location = glGetAttribLocation @program, name.to_s
296
+ location = Gl.glGetAttribLocation @program, name.to_s
296
297
  raise ShaderAttributeError, "No #{name} attribute specified in program" if location == INVALID_LOCATION
297
298
  @attribute_locations[name] = location
298
299
  end
@@ -300,15 +301,15 @@ module Ashton
300
301
 
301
302
  protected
302
303
  def compile(type, source)
303
- shader = glCreateShader type
304
- glShaderSource shader, source
305
- glCompileShader shader
304
+ shader = Gl.glCreateShader type
305
+ Gl.glShaderSource shader, source
306
+ Gl.glCompileShader shader
306
307
 
307
- unless glGetShaderiv shader, GL_COMPILE_STATUS
308
- error = glGetShaderInfoLog shader
308
+ unless Gl.glGetShaderiv shader, Gl::GL_COMPILE_STATUS
309
+ error = Gl.glGetShaderInfoLog shader
309
310
  error_lines = error.scan(/0\((\d+)\)+/m).map {|num| num.first.to_i }.uniq
310
311
 
311
- if type == GL_VERTEX_SHADER
312
+ if type == Gl::GL_VERTEX_SHADER
312
313
  type_name = "Vertex"
313
314
  source = @vertex_source
314
315
  else
@@ -326,12 +327,12 @@ module Ashton
326
327
 
327
328
  protected
328
329
  def link
329
- @program = glCreateProgram
330
- glAttachShader @program, @vertex
331
- glAttachShader @program, @fragment
332
- glLinkProgram @program
330
+ @program = Gl.glCreateProgram
331
+ Gl.glAttachShader @program, @vertex
332
+ Gl.glAttachShader @program, @fragment
333
+ Gl.glLinkProgram @program
333
334
 
334
- unless glGetProgramiv @program, GL_LINK_STATUS
335
+ unless Gl.glGetProgramiv @program, Gl::GL_LINK_STATUS
335
336
  raise ShaderLinkError, "Shader link error: #{glGetProgramInfoLog(@program)}"
336
337
  end
337
338
 
@@ -46,23 +46,23 @@ module Ashton
46
46
  # TODO: Ideally we'd draw the image in replacement mode, but Gosu doesn't support that.
47
47
  $window.gl do
48
48
  info = image.gl_tex_info
49
- glEnable GL_TEXTURE_2D
50
- glBindTexture GL_TEXTURE_2D, info.tex_name
51
- glEnable GL_BLEND
52
- glBlendFunc GL_ONE, GL_ZERO
49
+ Gl.glEnable Gl::GL_TEXTURE_2D
50
+ Gl.glBindTexture Gl::GL_TEXTURE_2D, info.tex_name
51
+ Gl.glEnable Gl::GL_BLEND
52
+ Gl.glBlendFunc Gl::GL_ONE, Gl::GL_ZERO
53
53
 
54
- glBegin GL_QUADS do
55
- glTexCoord2d info.left, info.top
56
- glVertex2d 0, height # BL
54
+ Gl.glBegin Gl::GL_QUADS do
55
+ Gl.glTexCoord2d info.left, info.top
56
+ Gl.glVertex2d 0, height # BL
57
57
 
58
- glTexCoord2d info.left, info.bottom
59
- glVertex2d 0, 0 # TL
58
+ Gl.glTexCoord2d info.left, info.bottom
59
+ Gl.glVertex2d 0, 0 # TL
60
60
 
61
- glTexCoord2d info.right, info.bottom
62
- glVertex2d width, 0 # TR
61
+ Gl.glTexCoord2d info.right, info.bottom
62
+ Gl.glVertex2d width, 0 # TR
63
63
 
64
- glTexCoord2d info.right, info.top
65
- glVertex2d width, height # BR
64
+ Gl.glTexCoord2d info.right, info.top
65
+ Gl.glVertex2d width, height # BR
66
66
  end
67
67
  end
68
68
  end
@@ -98,14 +98,14 @@ module Ashton
98
98
  color = options[:color]
99
99
  color = color.to_opengl if color.is_a? Gosu::Color
100
100
 
101
- glBindFramebufferEXT GL_FRAMEBUFFER_EXT, fbo_id unless rendering?
101
+ Gl.glBindFramebufferEXT Gl::GL_FRAMEBUFFER_EXT, fbo_id unless rendering?
102
102
 
103
- glDisable GL_BLEND # Need to replace the alpha too.
104
- glClearColor(*color)
105
- glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
106
- glEnable GL_BLEND
103
+ Gl.glDisable Gl::GL_BLEND # Need to replace the alpha too.
104
+ Gl.glClearColor(*color)
105
+ Gl.glClear Gl::GL_COLOR_BUFFER_BIT | Gl::GL_DEPTH_BUFFER_BIT
106
+ Gl.glEnable Gl::GL_BLEND
107
107
 
108
- glBindFramebufferEXT GL_FRAMEBUFFER_EXT, 0 unless rendering?
108
+ Gl.glBindFramebufferEXT Gl::GL_FRAMEBUFFER_EXT, 0 unless rendering?
109
109
 
110
110
  nil
111
111
  end
@@ -123,21 +123,21 @@ module Ashton
123
123
  @rendering = true
124
124
 
125
125
  # Project onto the texture itself, using Gosu (inverted) coordinates.
126
- glPushMatrix
127
- glMatrixMode GL_PROJECTION
128
- glLoadIdentity
129
- glViewport 0, 0, width, height
130
- glOrtho 0, width, height, 0, -1, 1
126
+ Gl.glPushMatrix
127
+ Gl.glMatrixMode Gl::GL_PROJECTION
128
+ Gl.glLoadIdentity
129
+ Gl.glViewport 0, 0, width, height
130
+ Gl.glOrtho 0, width, height, 0, -1, 1
131
131
 
132
132
  begin
133
133
  yield self
134
134
  ensure
135
135
  $window.flush # Force all the drawing to draw now!
136
- glBindFramebufferEXT GL_FRAMEBUFFER_EXT, 0
136
+ Gl.glBindFramebufferEXT Gl::GL_FRAMEBUFFER_EXT, 0
137
137
 
138
138
  @rendering = false
139
139
 
140
- glPopMatrix
140
+ Gl.glPopMatrix
141
141
 
142
142
  cache.refresh # Force lazy reloading of the cache.
143
143
  end
@@ -1,3 +1,3 @@
1
1
  module Ashton
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -8,8 +8,8 @@ module Ashton
8
8
  public
9
9
  # Copy the window contents into the buffer.
10
10
  def capture
11
- glBindTexture GL_TEXTURE_2D, id
12
- glCopyTexImage2D GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, width, height, 0
11
+ Gl.glBindTexture Gl::GL_TEXTURE_2D, id
12
+ Gl.glCopyTexImage2D Gl::GL_TEXTURE_2D, 0, Gl::GL_RGBA8, 0, 0, width, height, 0
13
13
  self
14
14
  end
15
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ashton
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:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-01 00:00:00.000000000 Z
12
+ date: 2014-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: opengl
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.8.0.pre1
21
+ version: 0.9.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.8.0.pre1
29
+ version: 0.9.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: gosu
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.7.45
37
+ version: '0.7'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.7.45
45
+ version: '0.7'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rake-compiler
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -190,6 +190,7 @@ files:
190
190
  - lib/ashton/signed_distance_field.rb
191
191
  - lib/ashton/lighting/manager.rb
192
192
  - lib/ashton/lighting/light_source.rb
193
+ - lib/ashton/1.9/ashton.so
193
194
  - lib/ashton/gosu_ext/image.rb
194
195
  - lib/ashton/gosu_ext/gosu_module.rb
195
196
  - lib/ashton/gosu_ext/font.rb
@@ -311,10 +312,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
312
  version: '0'
312
313
  segments:
313
314
  - 0
314
- hash: 1251081987634460007
315
+ hash: -4267932670615509659
315
316
  requirements: []
316
317
  rubyforge_project: ashton
317
- rubygems_version: 1.8.23
318
+ rubygems_version: 1.8.23.2
318
319
  signing_key:
319
320
  specification_version: 3
320
321
  summary: Extra special effects, such as shader, for the Gosu game-development library