rays 0.3.10 → 0.3.12
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 +4 -4
- data/.doc/ext/rays/image.cpp +10 -0
- data/.doc/ext/rays/painter.cpp +49 -1
- data/.doc/ext/rays/polygon.cpp +1 -1
- data/.doc/ext/rays/shader.cpp +8 -6
- data/.github/workflows/release-gem.yml +4 -1
- data/.github/workflows/test.yml +4 -4
- data/.github/workflows/utils.rb +88 -17
- data/ChangeLog.md +24 -0
- data/Gemfile.lock +6 -5
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/ext/rays/extconf.rb +3 -4
- data/ext/rays/image.cpp +11 -0
- data/ext/rays/painter.cpp +53 -1
- data/ext/rays/polygon.cpp +1 -1
- data/ext/rays/shader.cpp +8 -6
- data/include/rays/coord.h +6 -6
- data/include/rays/defs.h +2 -0
- data/include/rays/image.h +11 -1
- data/include/rays/painter.h +19 -0
- data/include/rays/ruby.h +2 -2
- data/include/rays/shader.h +5 -3
- data/include/rays.h +2 -2
- data/lib/rays/extension.rb +8 -2
- data/lib/rays/image.rb +2 -1
- data/lib/rays/shader.rb +13 -4
- data/rays.gemspec +3 -4
- data/src/bitmap.h +4 -0
- data/src/color_space.cpp +2 -42
- data/src/coord.h +10 -0
- data/src/font.cpp +1 -1
- data/src/image.cpp +85 -11
- data/src/ios/bitmap.mm +5 -32
- data/src/ios/rays.mm +3 -3
- data/src/opengl/bitmap.cpp +41 -0
- data/src/opengl/color_space.cpp +51 -0
- data/src/{color_space.h → opengl/color_space.h} +2 -2
- data/src/{frame_buffer.cpp → opengl/frame_buffer.cpp} +1 -1
- data/src/{frame_buffer.h → opengl/frame_buffer.h} +2 -2
- data/src/{ios → opengl/ios}/opengl.mm +3 -3
- data/src/{opengl.h → opengl/opengl.h} +2 -6
- data/src/{osx → opengl/osx}/opengl.mm +3 -3
- data/src/opengl/painter.cpp +1020 -0
- data/src/{render_buffer.cpp → opengl/render_buffer.cpp} +1 -1
- data/src/{render_buffer.h → opengl/render_buffer.h} +2 -2
- data/src/{sdl → opengl/sdl}/opengl.cpp +10 -3
- data/src/{shader.cpp → opengl/shader.cpp} +69 -53
- data/src/{shader.h → opengl/shader.h} +12 -8
- data/src/{shader_program.cpp → opengl/shader_program.cpp} +24 -10
- data/src/{shader_program.h → opengl/shader_program.h} +4 -3
- data/src/{shader_source.cpp → opengl/shader_source.cpp} +2 -4
- data/src/{shader_source.h → opengl/shader_source.h} +2 -2
- data/src/{texture.cpp → opengl/texture.cpp} +18 -7
- data/src/opengl/texture.h +21 -0
- data/src/{win32 → opengl/win32}/opengl.cpp +4 -3
- data/src/osx/bitmap.mm +6 -34
- data/src/osx/rays.mm +3 -3
- data/src/painter.cpp +96 -925
- data/src/painter.h +223 -11
- data/src/polygon.cpp +38 -13
- data/src/renderer.h +22 -0
- data/src/sdl/bitmap.cpp +5 -33
- data/src/sdl/font.cpp +358 -9
- data/src/sdl/rays.cpp +8 -3
- data/src/texture.h +6 -3
- data/src/win32/bitmap.cpp +6 -34
- data/src/win32/rays.cpp +3 -3
- data/test/test_painter.rb +36 -25
- data/test/test_painter_batch.rb +254 -0
- metadata +31 -24
- /data/src/{opengl.cpp → opengl/opengl.cpp} +0 -0
data/include/rays/ruby.h
CHANGED
data/include/rays/shader.h
CHANGED
|
@@ -98,15 +98,17 @@ namespace Rays
|
|
|
98
98
|
ShaderEnv (
|
|
99
99
|
const NameList& attribute_position_names = {},
|
|
100
100
|
const NameList& attribute_texcoord_names = {},
|
|
101
|
+
const NameList& attribute_texcoord_min_names = {},
|
|
102
|
+
const NameList& attribute_texcoord_max_names = {},
|
|
101
103
|
const NameList& attribute_color_names = {},
|
|
102
104
|
const char* varying_position_name = NULL,
|
|
103
105
|
const char* varying_texcoord_name = NULL,
|
|
106
|
+
const char* varying_texcoord_min_name = NULL,
|
|
107
|
+
const char* varying_texcoord_max_name = NULL,
|
|
104
108
|
const char* varying_color_name = NULL,
|
|
105
109
|
const NameList& uniform_position_matrix_names = {},
|
|
106
110
|
const NameList& uniform_texcoord_matrix_names = {},
|
|
107
|
-
const NameList&
|
|
108
|
-
const NameList& uniform_texcoord_max_names = {},
|
|
109
|
-
const NameList& uniform_texcoord_offset_names = {},
|
|
111
|
+
const NameList& uniform_texcoord_pixel_names = {},
|
|
110
112
|
const NameList& uniform_texture_names = {},
|
|
111
113
|
uint flags = 0);
|
|
112
114
|
|
data/include/rays.h
CHANGED
data/lib/rays/extension.rb
CHANGED
|
@@ -5,8 +5,10 @@ module Rays
|
|
|
5
5
|
|
|
6
6
|
module_function
|
|
7
7
|
|
|
8
|
-
def name()
|
|
9
|
-
super.split('::')[-2]
|
|
8
|
+
def name(downcase = false)
|
|
9
|
+
super().split('::')[-2].then {|s|
|
|
10
|
+
downcase ? s.gsub(/([a-z])([A-Z])/) {"#{$1}-#{$2}"}.downcase : s
|
|
11
|
+
}
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def version()
|
|
@@ -29,6 +31,10 @@ module Rays
|
|
|
29
31
|
root_dir 'ext'
|
|
30
32
|
end
|
|
31
33
|
|
|
34
|
+
def lib_name()
|
|
35
|
+
"#{name true}.dll" if /mswin|ming|cygwin/.match? RUBY_PLATFORM
|
|
36
|
+
end
|
|
37
|
+
|
|
32
38
|
end# Extension
|
|
33
39
|
|
|
34
40
|
|
data/lib/rays/image.rb
CHANGED
data/lib/rays/shader.rb
CHANGED
|
@@ -17,10 +17,19 @@ module Rays
|
|
|
17
17
|
setup(
|
|
18
18
|
fragment_shader_source, vertex_shader_source,
|
|
19
19
|
builtin_variable_names&.values_at(
|
|
20
|
-
:attribute_position,
|
|
21
|
-
|
|
22
|
-
:
|
|
23
|
-
:
|
|
20
|
+
:attribute_position,
|
|
21
|
+
:attribute_texcoord,
|
|
22
|
+
:attribute_texcoord_min,
|
|
23
|
+
:attribute_texcoord_max,
|
|
24
|
+
:attribute_color,
|
|
25
|
+
:varying_position,
|
|
26
|
+
:varying_texcoord,
|
|
27
|
+
:varying_texcoord_min,
|
|
28
|
+
:varying_texcoord_max,
|
|
29
|
+
:varying_color,
|
|
30
|
+
:uniform_position_matrix,
|
|
31
|
+
:uniform_texcoord_matrix,
|
|
32
|
+
:uniform_texcoord_pixel,
|
|
24
33
|
:uniform_texture),
|
|
25
34
|
ignore_no_uniform_location_error)
|
|
26
35
|
|
data/rays.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
ext = Rays::Extension
|
|
13
|
-
name = ext.name
|
|
13
|
+
name = ext.name true
|
|
14
14
|
rdocs = glob.call *%w[README .doc/ext/**/*.cpp]
|
|
15
15
|
|
|
16
16
|
s.name = name
|
|
@@ -25,14 +25,13 @@ Gem::Specification.new do |s|
|
|
|
25
25
|
s.platform = Gem::Platform::RUBY
|
|
26
26
|
s.required_ruby_version = '>= 3.0.0'
|
|
27
27
|
|
|
28
|
-
s.add_dependency 'xot', '~> 0.3.
|
|
29
|
-
s.add_dependency 'rucy', '~> 0.3.
|
|
28
|
+
s.add_dependency 'xot', '~> 0.3.12'
|
|
29
|
+
s.add_dependency 'rucy', '~> 0.3.12'
|
|
30
30
|
|
|
31
31
|
s.files = `git ls-files`.split $/
|
|
32
32
|
s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
|
|
33
33
|
s.test_files = s.files.grep %r{^(test|spec|features)/}
|
|
34
34
|
s.extra_rdoc_files = rdocs.to_a
|
|
35
|
-
s.has_rdoc = true
|
|
36
35
|
|
|
37
36
|
s.metadata['msys2_mingw_dependencies'] = 'glew'
|
|
38
37
|
|
data/src/bitmap.h
CHANGED
|
@@ -16,6 +16,10 @@ namespace Rays
|
|
|
16
16
|
class RawFont;
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
void Bitmap_setup (
|
|
20
|
+
Bitmap* bitmap, int w, int h, const ColorSpace& cs,
|
|
21
|
+
const void* pixels = NULL, bool clear_pixels = true);
|
|
22
|
+
|
|
19
23
|
Bitmap Bitmap_from (const Texture& texture);
|
|
20
24
|
|
|
21
25
|
void Bitmap_draw_string (
|
data/src/color_space.cpp
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#include "color_space.h"
|
|
1
|
+
#include "rays/color_space.h"
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
#include <xot/util.h>
|
|
@@ -133,7 +133,7 @@ namespace Rays
|
|
|
133
133
|
ColorSpace::has_alpha () const
|
|
134
134
|
{
|
|
135
135
|
return
|
|
136
|
-
(ALPHA_FIRST <= type_ && type_ <= ALPHA_LAST) ||
|
|
136
|
+
(ALPHA_FIRST <= (int) type_ && (int) type_ <= ALPHA_LAST) ||
|
|
137
137
|
type_ == RGBA_8888 || type_ == ARGB_8888 ||
|
|
138
138
|
type_ == BGRA_8888 || type_ == ABGR_8888 ||
|
|
139
139
|
type_ == RGBA_float || type_ == ARGB_float ||
|
|
@@ -194,44 +194,4 @@ namespace Rays
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
|
|
197
|
-
void
|
|
198
|
-
ColorSpace_get_gl_format_and_type (
|
|
199
|
-
GLenum* format, GLenum* type, const ColorSpace& cs)
|
|
200
|
-
{
|
|
201
|
-
if (!format && !type)
|
|
202
|
-
argument_error(__FILE__, __LINE__);
|
|
203
|
-
|
|
204
|
-
if (!cs)
|
|
205
|
-
invalid_state_error(__FILE__, __LINE__);
|
|
206
|
-
|
|
207
|
-
if (format)
|
|
208
|
-
{
|
|
209
|
-
if (cs.is_rgb()) *format = cs.has_alpha() ? GL_RGBA : GL_RGB;
|
|
210
|
-
#ifndef IOS
|
|
211
|
-
else if (cs.is_bgr()) *format = cs.has_alpha() ? GL_BGRA : GL_BGR;
|
|
212
|
-
#endif
|
|
213
|
-
else if (cs.is_gray()) *format = GL_LUMINANCE;
|
|
214
|
-
else if (cs.is_alpha()) *format = GL_ALPHA;
|
|
215
|
-
else
|
|
216
|
-
rays_error(__FILE__, __LINE__, "invalid color space.");
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (type)
|
|
220
|
-
{
|
|
221
|
-
if (cs.is_float())
|
|
222
|
-
*type = GL_FLOAT;
|
|
223
|
-
else switch (cs.bpc())
|
|
224
|
-
{
|
|
225
|
-
case 8: *type = GL_UNSIGNED_BYTE; break;
|
|
226
|
-
case 16: *type = GL_UNSIGNED_SHORT; break;
|
|
227
|
-
#ifndef IOS
|
|
228
|
-
case 32: *type = GL_UNSIGNED_INT; break;
|
|
229
|
-
#endif
|
|
230
|
-
default:
|
|
231
|
-
rays_error(__FILE__, __LINE__, "invalid bpc.");
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
197
|
}// Rays
|
data/src/coord.h
CHANGED
|
@@ -21,12 +21,22 @@ namespace Rays
|
|
|
21
21
|
|
|
22
22
|
inline const Vec3& to_glm (const Coord3& val) {return *(const Vec3*) &val;}
|
|
23
23
|
|
|
24
|
+
inline Vec4& to_glm ( Coord4& val) {return *( Vec4*) &val;}
|
|
25
|
+
|
|
26
|
+
inline const Vec4& to_glm (const Coord4& val) {return *(const Vec4*) &val;}
|
|
27
|
+
|
|
24
28
|
template <typename T>
|
|
25
29
|
inline T& to_rays ( Vec3& val) {return *( T*) &val;}
|
|
26
30
|
|
|
27
31
|
template <typename T>
|
|
28
32
|
inline const T& to_rays (const Vec3& val) {return *(const T*) &val;}
|
|
29
33
|
|
|
34
|
+
template <typename T>
|
|
35
|
+
inline T& to_rays ( Vec4& val) {return *( T*) &val;}
|
|
36
|
+
|
|
37
|
+
template <typename T>
|
|
38
|
+
inline const T& to_rays (const Vec4& val) {return *(const T*) &val;}
|
|
39
|
+
|
|
30
40
|
|
|
31
41
|
}// Rays
|
|
32
42
|
|
data/src/font.cpp
CHANGED
data/src/image.cpp
CHANGED
|
@@ -5,13 +5,12 @@
|
|
|
5
5
|
#include <assert.h>
|
|
6
6
|
#include "rays/exception.h"
|
|
7
7
|
#include "rays/debug.h"
|
|
8
|
-
#include "opengl.h"
|
|
9
8
|
#include "bitmap.h"
|
|
10
9
|
#include "texture.h"
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
#if 0
|
|
14
|
-
#define PRINT_MODIFIED_FLAGS(message)
|
|
13
|
+
#define PRINT_MODIFIED_FLAGS(message) get_data(this)->print_modified_flags(message)
|
|
15
14
|
#else
|
|
16
15
|
#define PRINT_MODIFIED_FLAGS(message)
|
|
17
16
|
#endif
|
|
@@ -21,16 +20,16 @@ namespace Rays
|
|
|
21
20
|
{
|
|
22
21
|
|
|
23
22
|
|
|
24
|
-
struct Image::Data
|
|
23
|
+
struct ImageData : Image::Data
|
|
25
24
|
{
|
|
26
25
|
|
|
27
26
|
int width = 0, height = 0;
|
|
28
27
|
|
|
29
|
-
ColorSpace color_space;
|
|
30
|
-
|
|
31
28
|
float pixel_density = 1;
|
|
32
29
|
|
|
33
|
-
bool smooth
|
|
30
|
+
bool smooth = false;
|
|
31
|
+
|
|
32
|
+
ColorSpace color_space;
|
|
34
33
|
|
|
35
34
|
mutable Bitmap bitmap;
|
|
36
35
|
|
|
@@ -49,10 +48,23 @@ namespace Rays
|
|
|
49
48
|
};// Image::Data
|
|
50
49
|
|
|
51
50
|
|
|
51
|
+
static ImageData*
|
|
52
|
+
get_data (Image* image)
|
|
53
|
+
{
|
|
54
|
+
return (ImageData*) image->self.get();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static const ImageData*
|
|
58
|
+
get_data (const Image* image)
|
|
59
|
+
{
|
|
60
|
+
return (const ImageData*) image->self.get();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
52
64
|
static void
|
|
53
65
|
clear_modified_flags (Image* image)
|
|
54
66
|
{
|
|
55
|
-
|
|
67
|
+
ImageData* self = get_data(image);
|
|
56
68
|
|
|
57
69
|
if (self->bitmap) Bitmap_set_modified(&self->bitmap, false);
|
|
58
70
|
if (self->texture) self->texture.set_modified(false);
|
|
@@ -62,7 +74,7 @@ namespace Rays
|
|
|
62
74
|
invalidate_texture (Image* image)
|
|
63
75
|
{
|
|
64
76
|
image->bitmap();// update bitmap
|
|
65
|
-
image->
|
|
77
|
+
get_data(image)->texture = Texture();
|
|
66
78
|
}
|
|
67
79
|
|
|
68
80
|
static Bitmap&
|
|
@@ -70,7 +82,7 @@ namespace Rays
|
|
|
70
82
|
{
|
|
71
83
|
assert(image);
|
|
72
84
|
|
|
73
|
-
|
|
85
|
+
ImageData* self = get_data(image);
|
|
74
86
|
|
|
75
87
|
if (!*image)
|
|
76
88
|
{
|
|
@@ -113,7 +125,7 @@ namespace Rays
|
|
|
113
125
|
Texture&
|
|
114
126
|
Image_get_texture (Image& image)
|
|
115
127
|
{
|
|
116
|
-
|
|
128
|
+
ImageData* self = get_data(&image);
|
|
117
129
|
|
|
118
130
|
if (!image)
|
|
119
131
|
{
|
|
@@ -172,17 +184,30 @@ namespace Rays
|
|
|
172
184
|
}
|
|
173
185
|
|
|
174
186
|
|
|
187
|
+
Image::Data::~Data ()
|
|
188
|
+
{
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
void
|
|
192
|
+
Image::Data::preprocess (const Image*) const
|
|
193
|
+
{
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
|
|
175
197
|
Image::Image ()
|
|
198
|
+
: self(new ImageData())
|
|
176
199
|
{
|
|
177
200
|
}
|
|
178
201
|
|
|
179
202
|
Image::Image (
|
|
180
203
|
int width, int height, const ColorSpace& cs,
|
|
181
204
|
float pixel_density, bool smooth)
|
|
205
|
+
: self(new ImageData())
|
|
182
206
|
{
|
|
183
207
|
if (pixel_density <= 0)
|
|
184
208
|
argument_error(__FILE__, __LINE__, "invalid pixel_density.");
|
|
185
209
|
|
|
210
|
+
ImageData* self = get_data(this);
|
|
186
211
|
self->width = (int) (width * pixel_density);
|
|
187
212
|
self->height = (int) (height * pixel_density);
|
|
188
213
|
self->color_space = cs;
|
|
@@ -191,10 +216,12 @@ namespace Rays
|
|
|
191
216
|
}
|
|
192
217
|
|
|
193
218
|
Image::Image (const Bitmap& bitmap, float pixel_density, bool smooth)
|
|
219
|
+
: self(new ImageData())
|
|
194
220
|
{
|
|
195
221
|
if (pixel_density <= 0)
|
|
196
222
|
argument_error(__FILE__, __LINE__, "invalid pixel_density.");
|
|
197
223
|
|
|
224
|
+
ImageData* self = get_data(this);
|
|
198
225
|
self->bitmap = bitmap;
|
|
199
226
|
self->width = bitmap.width();
|
|
200
227
|
self->height = bitmap.height();
|
|
@@ -203,6 +230,11 @@ namespace Rays
|
|
|
203
230
|
self->smooth = smooth;
|
|
204
231
|
}
|
|
205
232
|
|
|
233
|
+
Image::Image (Data* data)
|
|
234
|
+
: self(data)
|
|
235
|
+
{
|
|
236
|
+
}
|
|
237
|
+
|
|
206
238
|
Image::~Image ()
|
|
207
239
|
{
|
|
208
240
|
}
|
|
@@ -210,12 +242,16 @@ namespace Rays
|
|
|
210
242
|
Image
|
|
211
243
|
Image::dup () const
|
|
212
244
|
{
|
|
245
|
+
self->preprocess(this);
|
|
246
|
+
|
|
213
247
|
return Image(bitmap().dup(), pixel_density());
|
|
214
248
|
}
|
|
215
249
|
|
|
216
250
|
void
|
|
217
251
|
Image::save (const char* path)
|
|
218
252
|
{
|
|
253
|
+
self->preprocess(this);
|
|
254
|
+
|
|
219
255
|
if (!*this)
|
|
220
256
|
invalid_state_error(__FILE__, __LINE__);
|
|
221
257
|
|
|
@@ -225,32 +261,47 @@ namespace Rays
|
|
|
225
261
|
coord
|
|
226
262
|
Image::width () const
|
|
227
263
|
{
|
|
264
|
+
self->preprocess(this);
|
|
265
|
+
|
|
266
|
+
const ImageData* self = get_data(this);
|
|
228
267
|
return self->width / self->pixel_density;
|
|
229
268
|
}
|
|
230
269
|
|
|
231
270
|
coord
|
|
232
271
|
Image::height () const
|
|
233
272
|
{
|
|
273
|
+
self->preprocess(this);
|
|
274
|
+
|
|
275
|
+
const ImageData* self = get_data(this);
|
|
234
276
|
return self->height / self->pixel_density;
|
|
235
277
|
}
|
|
236
278
|
|
|
237
279
|
const ColorSpace&
|
|
238
280
|
Image::color_space () const
|
|
239
281
|
{
|
|
282
|
+
self->preprocess(this);
|
|
283
|
+
|
|
284
|
+
const ImageData* self = get_data(this);
|
|
240
285
|
return self->color_space;
|
|
241
286
|
}
|
|
242
287
|
|
|
243
288
|
float
|
|
244
289
|
Image::pixel_density () const
|
|
245
290
|
{
|
|
291
|
+
self->preprocess(this);
|
|
292
|
+
|
|
293
|
+
const ImageData* self = get_data(this);
|
|
246
294
|
return self->pixel_density;
|
|
247
295
|
}
|
|
248
296
|
|
|
249
297
|
void
|
|
250
298
|
Image::set_smooth (bool smooth)
|
|
251
299
|
{
|
|
252
|
-
|
|
300
|
+
self->preprocess(this);
|
|
301
|
+
|
|
302
|
+
ImageData* self = get_data(this);
|
|
253
303
|
|
|
304
|
+
if (smooth == self->smooth) return;
|
|
254
305
|
self->smooth = smooth;
|
|
255
306
|
invalidate_texture(this);
|
|
256
307
|
}
|
|
@@ -258,12 +309,17 @@ namespace Rays
|
|
|
258
309
|
bool
|
|
259
310
|
Image::smooth () const
|
|
260
311
|
{
|
|
312
|
+
self->preprocess(this);
|
|
313
|
+
|
|
314
|
+
const ImageData* self = get_data(this);
|
|
261
315
|
return self->smooth;
|
|
262
316
|
}
|
|
263
317
|
|
|
264
318
|
Painter
|
|
265
319
|
Image::painter ()
|
|
266
320
|
{
|
|
321
|
+
self->preprocess(this);
|
|
322
|
+
|
|
267
323
|
Painter p;
|
|
268
324
|
p.bind(*this);
|
|
269
325
|
return p;
|
|
@@ -272,6 +328,9 @@ namespace Rays
|
|
|
272
328
|
Bitmap&
|
|
273
329
|
Image::bitmap (bool modify)
|
|
274
330
|
{
|
|
331
|
+
self->preprocess(this);
|
|
332
|
+
|
|
333
|
+
ImageData* self = get_data(this);
|
|
275
334
|
if (modify)
|
|
276
335
|
{
|
|
277
336
|
if (!self->bitmap) get_bitmap(this);
|
|
@@ -288,6 +347,9 @@ namespace Rays
|
|
|
288
347
|
|
|
289
348
|
Image::operator bool () const
|
|
290
349
|
{
|
|
350
|
+
self->preprocess(this);
|
|
351
|
+
|
|
352
|
+
const ImageData* self = get_data(this);
|
|
291
353
|
return
|
|
292
354
|
self->width > 0 &&
|
|
293
355
|
self->height > 0 &&
|
|
@@ -301,5 +363,17 @@ namespace Rays
|
|
|
301
363
|
return !operator bool();
|
|
302
364
|
}
|
|
303
365
|
|
|
366
|
+
bool
|
|
367
|
+
operator == (const Image& lhs, const Image& rhs)
|
|
368
|
+
{
|
|
369
|
+
return lhs.self == rhs.self;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
bool
|
|
373
|
+
operator != (const Image& lhs, const Image& rhs)
|
|
374
|
+
{
|
|
375
|
+
return !operator==(lhs, rhs);
|
|
376
|
+
}
|
|
377
|
+
|
|
304
378
|
|
|
305
379
|
}// Rays
|
data/src/ios/bitmap.mm
CHANGED
|
@@ -6,10 +6,8 @@
|
|
|
6
6
|
#import <MobileCoreServices/UTCoreTypes.h>
|
|
7
7
|
#include <xot/util.h>
|
|
8
8
|
#include "rays/exception.h"
|
|
9
|
-
#include "../color_space.h"
|
|
10
9
|
#include "../font.h"
|
|
11
10
|
#include "../texture.h"
|
|
12
|
-
#include "../frame_buffer.h"
|
|
13
11
|
|
|
14
12
|
|
|
15
13
|
namespace Rays
|
|
@@ -131,11 +129,10 @@ namespace Rays
|
|
|
131
129
|
};// Bitmap::Data
|
|
132
130
|
|
|
133
131
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
Bitmap* bitmap,
|
|
137
|
-
|
|
138
|
-
const void* pixels = NULL, bool clear_pixels = true)
|
|
132
|
+
void
|
|
133
|
+
Bitmap_setup (
|
|
134
|
+
Bitmap* bitmap, int w, int h, const ColorSpace& cs,
|
|
135
|
+
const void* pixels, bool clear_pixels)
|
|
139
136
|
{
|
|
140
137
|
if (w <= 0)
|
|
141
138
|
argument_error(__FILE__, __LINE__);
|
|
@@ -162,30 +159,6 @@ namespace Rays
|
|
|
162
159
|
memset(self->pixels, 0, size);
|
|
163
160
|
}
|
|
164
161
|
|
|
165
|
-
Bitmap
|
|
166
|
-
Bitmap_from (const Texture& tex)
|
|
167
|
-
{
|
|
168
|
-
if (!tex)
|
|
169
|
-
argument_error(__FILE__, __LINE__);
|
|
170
|
-
|
|
171
|
-
Bitmap bmp;
|
|
172
|
-
setup_bitmap(
|
|
173
|
-
&bmp, tex.width(), tex.height(), tex.color_space(), NULL, false);
|
|
174
|
-
|
|
175
|
-
GLenum format, type;
|
|
176
|
-
ColorSpace_get_gl_format_and_type(&format, &type, tex.color_space());
|
|
177
|
-
|
|
178
|
-
FrameBuffer fb(tex);
|
|
179
|
-
FrameBufferBinder binder(fb.id());
|
|
180
|
-
|
|
181
|
-
for (int y = 0; y < bmp.height(); ++y)
|
|
182
|
-
{
|
|
183
|
-
GLvoid* ptr = (GLvoid*) bmp.at<uchar>(0, y);
|
|
184
|
-
glReadPixels(0, y, bmp.width(), 1, format, type, ptr);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return bmp;
|
|
188
|
-
}
|
|
189
162
|
|
|
190
163
|
void
|
|
191
164
|
Bitmap_draw_image (
|
|
@@ -318,7 +291,7 @@ namespace Rays
|
|
|
318
291
|
Bitmap::Bitmap (
|
|
319
292
|
int width, int height, const ColorSpace& color_space, const void* pixels)
|
|
320
293
|
{
|
|
321
|
-
|
|
294
|
+
Bitmap_setup(this, width, height, color_space, pixels);
|
|
322
295
|
}
|
|
323
296
|
|
|
324
297
|
Bitmap::~Bitmap ()
|
data/src/ios/rays.mm
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
#import <Foundation/Foundation.h>
|
|
6
6
|
#include "rays/exception.h"
|
|
7
|
-
#include "../
|
|
7
|
+
#include "../renderer.h"
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
namespace Rays
|
|
@@ -29,7 +29,7 @@ namespace Rays
|
|
|
29
29
|
|
|
30
30
|
global::pool = [[NSAutoreleasePool alloc] init];
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
Renderer_init();
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
void
|
|
@@ -38,7 +38,7 @@ namespace Rays
|
|
|
38
38
|
if (!global::pool)
|
|
39
39
|
rays_error(__FILE__, __LINE__, "not initialized.");
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Renderer_fin();
|
|
42
42
|
|
|
43
43
|
[global::pool release];
|
|
44
44
|
global::pool = nil;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#include "../bitmap.h"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
#include "rays/exception.h"
|
|
5
|
+
#include "../texture.h"
|
|
6
|
+
#include "opengl.h"
|
|
7
|
+
#include "color_space.h"
|
|
8
|
+
#include "frame_buffer.h"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
namespace Rays
|
|
12
|
+
{
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
Bitmap
|
|
16
|
+
Bitmap_from (const Texture& tex)
|
|
17
|
+
{
|
|
18
|
+
if (!tex)
|
|
19
|
+
argument_error(__FILE__, __LINE__);
|
|
20
|
+
|
|
21
|
+
Bitmap bmp;
|
|
22
|
+
Bitmap_setup(
|
|
23
|
+
&bmp, tex.width(), tex.height(), tex.color_space(), NULL, false);
|
|
24
|
+
|
|
25
|
+
GLenum format, type;
|
|
26
|
+
ColorSpace_get_gl_format_and_type(&format, &type, tex.color_space());
|
|
27
|
+
|
|
28
|
+
FrameBuffer fb(tex);
|
|
29
|
+
FrameBufferBinder binder(fb.id());
|
|
30
|
+
|
|
31
|
+
for (int y = 0; y < bmp.height(); ++y)
|
|
32
|
+
{
|
|
33
|
+
GLvoid* ptr = (GLvoid*) bmp.at<uchar>(0, y);
|
|
34
|
+
glReadPixels(0, y, bmp.width(), 1, format, type, ptr);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return bmp;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
}// Rays
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#include "color_space.h"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
#include "rays/exception.h"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
namespace Rays
|
|
8
|
+
{
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
void
|
|
12
|
+
ColorSpace_get_gl_format_and_type (
|
|
13
|
+
GLenum* format, GLenum* type, const ColorSpace& cs)
|
|
14
|
+
{
|
|
15
|
+
if (!format && !type)
|
|
16
|
+
argument_error(__FILE__, __LINE__);
|
|
17
|
+
|
|
18
|
+
if (!cs)
|
|
19
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
20
|
+
|
|
21
|
+
if (format)
|
|
22
|
+
{
|
|
23
|
+
if (cs.is_rgb()) *format = cs.has_alpha() ? GL_RGBA : GL_RGB;
|
|
24
|
+
#ifndef IOS
|
|
25
|
+
else if (cs.is_bgr()) *format = cs.has_alpha() ? GL_BGRA : GL_BGR;
|
|
26
|
+
#endif
|
|
27
|
+
else if (cs.is_gray()) *format = GL_LUMINANCE;
|
|
28
|
+
else if (cs.is_alpha()) *format = GL_ALPHA;
|
|
29
|
+
else
|
|
30
|
+
rays_error(__FILE__, __LINE__, "invalid color space.");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (type)
|
|
34
|
+
{
|
|
35
|
+
if (cs.is_float())
|
|
36
|
+
*type = GL_FLOAT;
|
|
37
|
+
else switch (cs.bpc())
|
|
38
|
+
{
|
|
39
|
+
case 8: *type = GL_UNSIGNED_BYTE; break;
|
|
40
|
+
case 16: *type = GL_UNSIGNED_SHORT; break;
|
|
41
|
+
#ifndef IOS
|
|
42
|
+
case 32: *type = GL_UNSIGNED_INT; break;
|
|
43
|
+
#endif
|
|
44
|
+
default:
|
|
45
|
+
rays_error(__FILE__, __LINE__, "invalid bpc.");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
}// Rays
|
|
@@ -105,7 +105,7 @@ namespace Rays
|
|
|
105
105
|
FrameBufferBinder binder(id());
|
|
106
106
|
|
|
107
107
|
glFramebufferTexture2D(
|
|
108
|
-
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture
|
|
108
|
+
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, Texture_get_id(texture), 0);
|
|
109
109
|
OpenGL_check_error(__FILE__, __LINE__);
|
|
110
110
|
|
|
111
111
|
self->texture = texture;
|