rays 0.1.28 → 0.1.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.doc/ext/rays/bitmap.cpp +1 -1
- data/.doc/ext/rays/bounds.cpp +1 -1
- data/.doc/ext/rays/camera.cpp +1 -1
- data/.doc/ext/rays/color.cpp +1 -1
- data/.doc/ext/rays/color_space.cpp +1 -1
- data/.doc/ext/rays/exception.cpp +45 -0
- data/.doc/ext/rays/font.cpp +1 -1
- data/.doc/ext/rays/image.cpp +1 -1
- data/.doc/ext/rays/matrix.cpp +1 -1
- data/.doc/ext/rays/native.cpp +35 -33
- data/.doc/ext/rays/noise.cpp +1 -1
- data/.doc/ext/rays/painter.cpp +1 -1
- data/.doc/ext/rays/point.cpp +1 -1
- data/.doc/ext/rays/polygon.cpp +1 -1
- data/.doc/ext/rays/polygon_line.cpp +1 -1
- data/.doc/ext/rays/polyline.cpp +1 -1
- data/.doc/ext/rays/shader.cpp +101 -7
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +1 -1
- data/ext/rays/bounds.cpp +1 -1
- data/ext/rays/camera.cpp +1 -1
- data/ext/rays/color.cpp +1 -1
- data/ext/rays/color_space.cpp +1 -1
- data/ext/rays/defs.h +1 -0
- data/ext/rays/exception.cpp +45 -0
- data/ext/rays/extconf.rb +1 -1
- data/ext/rays/font.cpp +1 -1
- data/ext/rays/image.cpp +1 -1
- data/ext/rays/matrix.cpp +1 -1
- data/ext/rays/native.cpp +35 -33
- data/ext/rays/noise.cpp +1 -1
- data/ext/rays/painter.cpp +1 -1
- data/ext/rays/point.cpp +1 -1
- data/ext/rays/polygon.cpp +1 -1
- data/ext/rays/polygon_line.cpp +1 -1
- data/ext/rays/polyline.cpp +1 -1
- data/ext/rays/shader.cpp +102 -6
- data/include/rays/exception.h +11 -0
- data/include/rays/ruby/bitmap.h +0 -1
- data/include/rays/ruby/bounds.h +0 -2
- data/include/rays/ruby/camera.h +0 -1
- data/include/rays/ruby/color.h +0 -2
- data/include/rays/ruby/color_space.h +0 -1
- data/include/rays/ruby/defs.h +30 -0
- data/include/rays/ruby/exception.h +28 -0
- data/include/rays/ruby/font.h +0 -1
- data/include/rays/ruby/image.h +0 -1
- data/include/rays/ruby/matrix.h +0 -1
- data/include/rays/ruby/painter.h +0 -1
- data/include/rays/ruby/point.h +0 -2
- data/include/rays/ruby/polygon.h +0 -1
- data/include/rays/ruby/polyline.h +0 -1
- data/include/rays/ruby/rays.h +0 -1
- data/include/rays/ruby/shader.h +0 -1
- data/include/rays/ruby.h +2 -0
- data/include/rays/shader.h +48 -1
- data/lib/rays/painter.rb +6 -5
- data/lib/rays/point.rb +1 -0
- data/lib/rays/shader.rb +18 -5
- data/rays.gemspec +3 -3
- data/src/exception.cpp +13 -0
- data/src/image.cpp +6 -4
- data/src/opengl.cpp +20 -7
- data/src/opengl.h +5 -3
- data/src/osx/font.mm +0 -2
- data/src/osx/opengl.mm +17 -2
- data/src/painter.cpp +181 -148
- data/src/shader.cpp +333 -53
- data/src/shader.h +53 -14
- data/src/shader_program.cpp +53 -27
- data/src/shader_program.h +8 -1
- data/src/shader_source.cpp +2 -2
- data/src/texture.cpp +80 -63
- data/test/helper.rb +1 -1
- data/test/test_point.rb +6 -5
- data/test/test_rays.rb +2 -2
- data/test/test_shader.rb +151 -14
- metadata +12 -7
data/src/shader_source.cpp
CHANGED
@@ -42,7 +42,7 @@ namespace Rays
|
|
42
42
|
GLint status = GL_FALSE;
|
43
43
|
glGetShaderiv(id, GL_COMPILE_STATUS, &status);
|
44
44
|
if (status == GL_FALSE)
|
45
|
-
|
45
|
+
shader_error(__FILE__, __LINE__, get_compile_log().c_str());
|
46
46
|
|
47
47
|
type = type_;
|
48
48
|
source = source_;
|
@@ -98,7 +98,7 @@ namespace Rays
|
|
98
98
|
const char*
|
99
99
|
ShaderSource::source () const
|
100
100
|
{
|
101
|
-
return self->source;
|
101
|
+
return self->is_valid() ? self->source.c_str() : NULL;
|
102
102
|
}
|
103
103
|
|
104
104
|
GLenum
|
data/src/texture.cpp
CHANGED
@@ -82,38 +82,6 @@ namespace Rays
|
|
82
82
|
return n;
|
83
83
|
}
|
84
84
|
|
85
|
-
static void
|
86
|
-
setup_texture (Texture::Data* self, const void* pixels = NULL)
|
87
|
-
{
|
88
|
-
assert(self && !self->has_id());
|
89
|
-
|
90
|
-
if (self->context)
|
91
|
-
invalid_state_error(__FILE__, __LINE__);
|
92
|
-
|
93
|
-
self->context = OpenGL_get_context();
|
94
|
-
if (!self->context)
|
95
|
-
opengl_error(__FILE__, __LINE__);
|
96
|
-
|
97
|
-
glGenTextures(1, &self->id);
|
98
|
-
glBindTexture(GL_TEXTURE_2D, self->id);
|
99
|
-
if (glIsTexture(self->id) == GL_FALSE)
|
100
|
-
opengl_error(__FILE__, __LINE__, "failed to create texture.");
|
101
|
-
|
102
|
-
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
103
|
-
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
104
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
105
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);//GL_LINEAR);
|
106
|
-
|
107
|
-
GLenum format, type;
|
108
|
-
ColorSpace_get_gl_format_and_type(&format, &type, self->color_space);
|
109
|
-
|
110
|
-
glTexImage2D(
|
111
|
-
GL_TEXTURE_2D, 0, format, self->width_pow2, self->height_pow2, 0,
|
112
|
-
format, type, pixels);
|
113
|
-
|
114
|
-
OpenGL_check_error(__FILE__, __LINE__);
|
115
|
-
}
|
116
|
-
|
117
85
|
template <int BytesPerPixel>
|
118
86
|
static inline void
|
119
87
|
copy_pixel (uchar* dest, const uchar* src)
|
@@ -179,7 +147,9 @@ namespace Rays
|
|
179
147
|
static void
|
180
148
|
copy_bitmap (Bitmap* dest, const Bitmap& src)
|
181
149
|
{
|
182
|
-
|
150
|
+
assert(dest);
|
151
|
+
|
152
|
+
if (!src)
|
183
153
|
argument_error(__FILE__, __LINE__);
|
184
154
|
|
185
155
|
int width = std::min(src.width(), dest->width());
|
@@ -196,51 +166,96 @@ namespace Rays
|
|
196
166
|
}
|
197
167
|
}
|
198
168
|
|
199
|
-
|
200
|
-
|
169
|
+
static std::shared_ptr<Bitmap>
|
170
|
+
resize_bitmap (const Bitmap& bitmap, int width, int height)
|
201
171
|
{
|
172
|
+
std::shared_ptr<Bitmap> bmp(
|
173
|
+
new Bitmap(width, height, bitmap.color_space()));
|
174
|
+
if (!*bmp)
|
175
|
+
rays_error(__FILE__, __LINE__);
|
176
|
+
|
177
|
+
copy_bitmap(bmp.get(), bitmap);
|
178
|
+
return bmp;
|
202
179
|
}
|
203
180
|
|
204
|
-
|
181
|
+
static void
|
182
|
+
setup_texture (
|
183
|
+
Texture::Data* self, int width, int height, const ColorSpace& cs,
|
184
|
+
const Bitmap* bitmap = NULL, bool npot = false)
|
205
185
|
{
|
206
|
-
|
207
|
-
|
186
|
+
assert(self && !self->has_id());
|
187
|
+
|
188
|
+
if (self->context)
|
189
|
+
invalid_state_error(__FILE__, __LINE__);
|
190
|
+
|
191
|
+
self->context = OpenGL_get_context();
|
192
|
+
if (!self->context)
|
193
|
+
opengl_error(__FILE__, __LINE__);
|
194
|
+
|
195
|
+
glGenTextures(1, &self->id);
|
196
|
+
glBindTexture(GL_TEXTURE_2D, self->id);
|
197
|
+
if (glIsTexture(self->id) == GL_FALSE)
|
198
|
+
opengl_error(__FILE__, __LINE__, "failed to create texture.");
|
199
|
+
|
200
|
+
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
201
|
+
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
202
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
203
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);//GL_LINEAR);
|
204
|
+
|
205
|
+
GLenum format, type;
|
206
|
+
ColorSpace_get_gl_format_and_type(&format, &type, cs);
|
207
|
+
|
208
|
+
if (npot)
|
209
|
+
{
|
210
|
+
// create non-power-of-two texture
|
211
|
+
glTexImage2D(
|
212
|
+
GL_TEXTURE_2D, 0, format, width, height, 0, format, type,
|
213
|
+
bitmap ? bitmap->pixels() : NULL);
|
214
|
+
npot = OpenGL_has_error();
|
215
|
+
}
|
216
|
+
|
217
|
+
if (!npot)
|
218
|
+
{
|
219
|
+
// create power-of-two texture
|
220
|
+
int width_pow2 = min_pow2(width);
|
221
|
+
int height_pow2 = min_pow2(height);
|
222
|
+
|
223
|
+
glTexImage2D(
|
224
|
+
GL_TEXTURE_2D, 0, format, width_pow2, height_pow2, 0, format, type,
|
225
|
+
bitmap ? resize_bitmap(*bitmap, width_pow2, height_pow2)->pixels() : NULL);
|
226
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
227
|
+
|
228
|
+
self->width_pow2 = width_pow2;
|
229
|
+
self->height_pow2 = height_pow2;
|
230
|
+
}
|
208
231
|
|
209
232
|
self->width = width;
|
210
233
|
self->height = height;
|
211
|
-
self->width_pow2 = min_pow2(width);
|
212
|
-
self->height_pow2 = min_pow2(height);
|
213
234
|
self->color_space = cs;
|
214
235
|
self->modified = true;
|
236
|
+
}
|
215
237
|
|
216
|
-
|
238
|
+
|
239
|
+
Texture::Texture ()
|
240
|
+
{
|
217
241
|
}
|
218
242
|
|
219
|
-
Texture::Texture (const
|
243
|
+
Texture::Texture (int width, int height, const ColorSpace& cs)
|
220
244
|
{
|
221
|
-
if (!
|
245
|
+
if (width <= 0 || height <= 0 || !cs)
|
222
246
|
argument_error(__FILE__, __LINE__);
|
223
247
|
|
224
|
-
self
|
225
|
-
|
226
|
-
self->width_pow2 = min_pow2(self->width);
|
227
|
-
self->height_pow2 = min_pow2(self->height);
|
228
|
-
self->color_space = bitmap.color_space();
|
229
|
-
self->modified = true;
|
230
|
-
|
231
|
-
Bitmap bmp = bitmap;
|
232
|
-
if (
|
233
|
-
self->width_pow2 != self->width ||
|
234
|
-
self->height_pow2 != self->height)
|
235
|
-
{
|
236
|
-
bmp = Bitmap(self->width_pow2, self->height_pow2, self->color_space);
|
237
|
-
if (!bmp)
|
238
|
-
rays_error(__FILE__, __LINE__);
|
248
|
+
setup_texture(self.get(), width, height, cs);
|
249
|
+
}
|
239
250
|
|
240
|
-
|
241
|
-
|
251
|
+
Texture::Texture (const Bitmap& bitmap)
|
252
|
+
{
|
253
|
+
if (!bitmap)
|
254
|
+
argument_error(__FILE__, __LINE__);
|
242
255
|
|
243
|
-
setup_texture(
|
256
|
+
setup_texture(
|
257
|
+
self.get(), bitmap.width(), bitmap.height(), bitmap.color_space(),
|
258
|
+
&bitmap);
|
244
259
|
}
|
245
260
|
|
246
261
|
Texture::~Texture ()
|
@@ -256,7 +271,8 @@ namespace Rays
|
|
256
271
|
int
|
257
272
|
Texture::reserved_width () const
|
258
273
|
{
|
259
|
-
|
274
|
+
int w = self->width_pow2;
|
275
|
+
return w > 0 ? w : self->width;
|
260
276
|
}
|
261
277
|
|
262
278
|
int
|
@@ -268,7 +284,8 @@ namespace Rays
|
|
268
284
|
int
|
269
285
|
Texture::reserved_height () const
|
270
286
|
{
|
271
|
-
|
287
|
+
int h = self->height_pow2;
|
288
|
+
return h > 0 ? h : self->height;
|
272
289
|
}
|
273
290
|
|
274
291
|
const ColorSpace&
|
data/test/helper.rb
CHANGED
data/test/test_point.rb
CHANGED
@@ -112,13 +112,14 @@ class TestPoint < Test::Unit::TestCase
|
|
112
112
|
|
113
113
|
def test_to_a()
|
114
114
|
o = point 1, 2, 3
|
115
|
-
assert_equal [1, 2],
|
116
|
-
assert_equal [1],
|
117
|
-
assert_equal [1, 2],
|
118
|
-
assert_equal [1, 2, 3],
|
115
|
+
assert_equal [1, 2], o.to_a
|
116
|
+
assert_equal [1], o.to_a(1)
|
117
|
+
assert_equal [1, 2], o.to_a(2)
|
118
|
+
assert_equal [1, 2, 3], o.to_a(3)
|
119
|
+
assert_equal [1, 2, 3, 1], o.to_a(4)
|
119
120
|
assert_raise(ArgumentError) {o.to_a(-1)}
|
120
121
|
assert_raise(ArgumentError) {o.to_a(0)}
|
121
|
-
assert_raise(ArgumentError) {o.to_a(
|
122
|
+
assert_raise(ArgumentError) {o.to_a(5)}
|
122
123
|
end
|
123
124
|
|
124
125
|
def test_index()
|
data/test/test_rays.rb
CHANGED
@@ -9,9 +9,9 @@ require_relative 'helper'
|
|
9
9
|
class TestRays < Test::Unit::TestCase
|
10
10
|
|
11
11
|
def test_init!()
|
12
|
-
assert_raise(
|
12
|
+
assert_raise(Rays::RaysError) {Rays.fin!}
|
13
13
|
assert Rays.init!
|
14
|
-
assert_raise(
|
14
|
+
assert_raise(Rays::RaysError) {Rays.init!}
|
15
15
|
assert Rays.fin!
|
16
16
|
end
|
17
17
|
|
data/test/test_shader.rb
CHANGED
@@ -6,32 +6,169 @@ require_relative 'helper'
|
|
6
6
|
|
7
7
|
class TestShader < Test::Unit::TestCase
|
8
8
|
|
9
|
-
def shader(
|
10
|
-
Rays::Shader.new
|
9
|
+
def shader(*a, **k)
|
10
|
+
Rays::Shader.new(*a, **k)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
Rays::Image.new
|
13
|
+
def image(w = 10, h = 10, &block)
|
14
|
+
Rays::Image.new(w, h).tap {|i| i.paint(&block) if block}
|
15
15
|
end
|
16
16
|
|
17
17
|
def color(*args)
|
18
18
|
Rays::Color.new(*args)
|
19
19
|
end
|
20
20
|
|
21
|
+
def vshader()
|
22
|
+
"void main() {gl_Position = vec4(0.0, 0.0, 0.0, 1.0);}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def fshader()
|
26
|
+
"void main() {gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def draw_shader(
|
30
|
+
fragment_shader_source, fill: 1, options: {}, uniforms: {}, &block)
|
31
|
+
|
32
|
+
image.tap do |img|
|
33
|
+
img.paint do |p|
|
34
|
+
p.shader shader(fragment_shader_source, **options.merge(uniforms))
|
35
|
+
block.call p.shader if block
|
36
|
+
p.fill(*fill)
|
37
|
+
p.stroke nil
|
38
|
+
p.rect img.bounds.move_to(0, 0)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
21
43
|
def test_initialize()
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
44
|
+
assert shader(fshader)
|
45
|
+
assert shader(fshader, vshader)
|
46
|
+
|
47
|
+
assert_raise(Rays::ShaderError) {shader "foo"}
|
48
|
+
assert_raise(Rays::ShaderError) {shader "foo", vshader}
|
49
|
+
assert_raise(Rays::ShaderError) {shader fshader, "foo"}
|
50
|
+
assert_raise(Rays::ShaderError) {shader vshader}
|
51
|
+
assert_raise(Rays::ShaderError) {shader fshader, fshader}
|
52
|
+
assert_raise(ArgumentError) {shader nil}
|
26
53
|
end
|
27
54
|
|
28
55
|
def test_shader()
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
56
|
+
assert_equal color(1, 0, 0, 1), draw_shader(<<~END, fill: [0, 1, 0, 1])[0, 0]
|
57
|
+
void main() {gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);}
|
58
|
+
END
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_uniform_int()
|
62
|
+
draw = -> (type, color_string, &b) {
|
63
|
+
draw_shader(<<~END) {|shader| b.call shader}[0, 0].to_a
|
64
|
+
uniform #{type} v;
|
65
|
+
float f(int value, int div) {
|
66
|
+
return float(value) / float(div);
|
67
|
+
}
|
68
|
+
void main() {
|
69
|
+
gl_FragColor = vec4(#{color_string});
|
70
|
+
}
|
71
|
+
END
|
72
|
+
}
|
73
|
+
assert_equal [1, 0, 0, 1], draw['int', 'f(v, 1), 0.0, 0.0, 1.0'] {|sh| sh.uniform :v, 1}
|
74
|
+
assert_equal [1, 0, 0, 1], draw['int', 'f(v, 1), 0.0, 0.0, 1.0'] {|sh| sh.uniform :v, [1]}
|
75
|
+
assert_equal [1, 1, 0, 1], draw['ivec2', 'f(v.x, 1), f(v.y, 2), 0.0, 1.0'] {|sh| sh.uniform :v, 1, 2}
|
76
|
+
assert_equal [1, 1, 0, 1], draw['ivec2', 'f(v.x, 1), f(v.y, 2), 0.0, 1.0'] {|sh| sh.uniform :v, [1, 2]}
|
77
|
+
assert_equal [1, 1, 1, 1], draw['ivec3', 'f(v.x, 1), f(v.y, 2), f(v.z, 3), 1.0'] {|sh| sh.uniform :v, 1, 2, 3}
|
78
|
+
assert_equal [1, 1, 1, 1], draw['ivec3', 'f(v.x, 1), f(v.y, 2), f(v.z, 3), 1.0'] {|sh| sh.uniform :v, [1, 2, 3]}
|
79
|
+
assert_equal [1, 1, 1, 1], draw['ivec4', 'f(v.x, 1), f(v.y, 2), f(v.z, 3), f(v.w, 4)'] {|sh| sh.uniform :v, 1, 2, 3, 4}
|
80
|
+
assert_equal [1, 1, 1, 1], draw['ivec4', 'f(v.x, 1), f(v.y, 2), f(v.z, 3), f(v.w, 4)'] {|sh| sh.uniform :v, [1, 2, 3, 4]}
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_uniform_float()
|
84
|
+
draw = -> (type, color_string, &b) {
|
85
|
+
draw_shader(<<~END) {|shader| b.call shader}[0, 0].to_a
|
86
|
+
uniform #{type} v;
|
87
|
+
float f(float value, int div) {
|
88
|
+
return value / float(div);
|
89
|
+
}
|
90
|
+
void main() {
|
91
|
+
gl_FragColor = vec4(#{color_string});
|
92
|
+
}
|
93
|
+
END
|
94
|
+
}
|
95
|
+
assert_equal [1, 0, 0, 1], draw['float', 'f(v, 1), 0.0, 0.0, 1.0'] {|sh| sh.uniform :v, 1.0}
|
96
|
+
assert_equal [1, 0, 0, 1], draw['float', 'f(v, 1), 0.0, 0.0, 1.0'] {|sh| sh.uniform :v, [1.0]}
|
97
|
+
assert_equal [1, 1, 0, 1], draw['vec2', 'f(v.x, 1), f(v.y, 2), 0.0, 1.0'] {|sh| sh.uniform :v, 1.0, 2.0}
|
98
|
+
assert_equal [1, 1, 0, 1], draw['vec2', 'f(v.x, 1), f(v.y, 2), 0.0, 1.0'] {|sh| sh.uniform :v, [1.0, 2.0]}
|
99
|
+
assert_equal [1, 1, 1, 1], draw['vec3', 'f(v.x, 1), f(v.y, 2), f(v.z, 3), 1.0'] {|sh| sh.uniform :v, 1.0, 2.0, 3.0}
|
100
|
+
assert_equal [1, 1, 1, 1], draw['vec3', 'f(v.x, 1), f(v.y, 2), f(v.z, 3), 1.0'] {|sh| sh.uniform :v, [1.0, 2.0, 3.0]}
|
101
|
+
assert_equal [1, 1, 1, 1], draw['vec4', 'f(v.x, 1), f(v.y, 2), f(v.z, 3), f(v.w, 4)'] {|sh| sh.uniform :v, 1.0, 2.0, 3.0, 4.0}
|
102
|
+
assert_equal [1, 1, 1, 1], draw['vec4', 'f(v.x, 1), f(v.y, 2), f(v.z, 3), f(v.w, 4)'] {|sh| sh.uniform :v, [1.0, 2.0, 3.0, 4.0]}
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_uniform_texture()
|
106
|
+
r, g, b = [[1, 0, 0], [0, 1, 0], [0, 0, 1]].map {|c| image {fill c; rect 10}}
|
107
|
+
assert_equal color(1, 1, 1, 1), draw_shader(<<~END, uniforms: {tex0: r, tex1: g, tex2: b})[0, 0]
|
108
|
+
uniform sampler2D tex0, tex1, tex2;
|
109
|
+
varying vec4 v_TexCoord;
|
110
|
+
void main() {
|
111
|
+
gl_FragColor = vec4(
|
112
|
+
texture2D(tex0, v_TexCoord.xy).r,
|
113
|
+
texture2D(tex1, v_TexCoord.xy).g,
|
114
|
+
texture2D(tex2, v_TexCoord.xy).b,
|
115
|
+
1.0);
|
116
|
+
}
|
117
|
+
END
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_uniform_error()
|
121
|
+
ignore = -> bool {{ignore_no_uniform_location_error: bool}}
|
122
|
+
|
123
|
+
assert_raise(Rays::ShaderError) {draw_shader 'void main() {}', uniforms: {val: 1.0}}
|
124
|
+
assert_raise(Rays::ShaderError) {draw_shader 'void main() {}', options: ignore[false], uniforms: {val: 1.0}}
|
125
|
+
assert_nothing_raised {draw_shader 'void main() {}', options: ignore[true], uniforms: {val: 1.0}}
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_shader_source()
|
129
|
+
assert_equal vshader, shader(fshader, vshader).vertex_shader_source
|
130
|
+
assert_equal fshader, shader(fshader, vshader).fragment_shader_source
|
131
|
+
|
132
|
+
assert_true shader(fshader).vertex_shader_source.then {|source|
|
133
|
+
%w[
|
134
|
+
a_Position a_TexCoord a_Color
|
135
|
+
v_Position v_TexCoord v_Color
|
136
|
+
u_PositionMatrix u_TexCoordMatrix
|
137
|
+
].all? {|name| source.include? name}
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_shader_env()
|
142
|
+
env = {
|
143
|
+
attribute_position: 'aP',
|
144
|
+
attribute_texcoord: ['aTC', 'aTC2'],
|
145
|
+
attribute_color: [],
|
146
|
+
varying_position: 'vP',
|
147
|
+
varying_texcoord: nil,
|
148
|
+
#varying_color: define nothing
|
149
|
+
uniform_position_matrix: nil,
|
150
|
+
#uniform_texcoord_matrix: define nothing
|
151
|
+
}
|
152
|
+
assert_true shader(fshader, nil, env).vertex_shader_source.then {|source|
|
153
|
+
%w[
|
154
|
+
aP
|
155
|
+
aTC
|
156
|
+
a_Color
|
157
|
+
vP
|
158
|
+
v_TexCoord
|
159
|
+
v_Color
|
160
|
+
u_PositionMatrix
|
161
|
+
u_TexCoordMatrix
|
162
|
+
].all? {|name| source.include? name}
|
163
|
+
}
|
164
|
+
|
165
|
+
assert_raise(ArgumentError) {shader(fshader, nil, {attribute_color: ''})}
|
166
|
+
assert_raise(ArgumentError) {shader(fshader, nil, {attribute_color: ['']})}
|
167
|
+
assert_raise(ArgumentError) {shader(fshader, nil, {attribute_color: [nil]})}
|
168
|
+
assert_raise(ArgumentError) {shader(fshader, nil, {attribute_color: ['C', '']})}
|
169
|
+
assert_raise(ArgumentError) {shader(fshader, nil, {attribute_color: ['C', nil]})}
|
170
|
+
|
171
|
+
assert_raise(ArgumentError) {shader(fshader, nil, {varying_color: ''})}
|
35
172
|
end
|
36
173
|
|
37
174
|
end# TestShader
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rays
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.30
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xot
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.30
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.
|
26
|
+
version: 0.1.30
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rucy
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1.
|
33
|
+
version: 0.1.30
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.1.
|
40
|
+
version: 0.1.30
|
41
41
|
description: This library helps you to develop graphics application with OpenGL.
|
42
42
|
email: xordog@gmail.com
|
43
43
|
executables: []
|
@@ -50,6 +50,7 @@ extra_rdoc_files:
|
|
50
50
|
- ".doc/ext/rays/color.cpp"
|
51
51
|
- ".doc/ext/rays/color_space.cpp"
|
52
52
|
- ".doc/ext/rays/defs.cpp"
|
53
|
+
- ".doc/ext/rays/exception.cpp"
|
53
54
|
- ".doc/ext/rays/font.cpp"
|
54
55
|
- ".doc/ext/rays/image.cpp"
|
55
56
|
- ".doc/ext/rays/matrix.cpp"
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- ".doc/ext/rays/color.cpp"
|
70
71
|
- ".doc/ext/rays/color_space.cpp"
|
71
72
|
- ".doc/ext/rays/defs.cpp"
|
73
|
+
- ".doc/ext/rays/exception.cpp"
|
72
74
|
- ".doc/ext/rays/font.cpp"
|
73
75
|
- ".doc/ext/rays/image.cpp"
|
74
76
|
- ".doc/ext/rays/matrix.cpp"
|
@@ -92,6 +94,7 @@ files:
|
|
92
94
|
- ext/rays/color_space.cpp
|
93
95
|
- ext/rays/defs.cpp
|
94
96
|
- ext/rays/defs.h
|
97
|
+
- ext/rays/exception.cpp
|
95
98
|
- ext/rays/extconf.rb
|
96
99
|
- ext/rays/font.cpp
|
97
100
|
- ext/rays/image.cpp
|
@@ -131,6 +134,8 @@ files:
|
|
131
134
|
- include/rays/ruby/camera.h
|
132
135
|
- include/rays/ruby/color.h
|
133
136
|
- include/rays/ruby/color_space.h
|
137
|
+
- include/rays/ruby/defs.h
|
138
|
+
- include/rays/ruby/exception.h
|
134
139
|
- include/rays/ruby/font.h
|
135
140
|
- include/rays/ruby/image.h
|
136
141
|
- include/rays/ruby/matrix.h
|
@@ -252,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
257
|
- !ruby/object:Gem::Version
|
253
258
|
version: '0'
|
254
259
|
requirements: []
|
255
|
-
rubygems_version: 3.
|
260
|
+
rubygems_version: 3.4.1
|
256
261
|
signing_key:
|
257
262
|
specification_version: 4
|
258
263
|
summary: A Drawing Engine using OpenGL.
|