rays 0.2.1 → 0.3.1
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/bitmap.cpp +99 -32
- data/.doc/ext/rays/bounds.cpp +16 -12
- data/.doc/ext/rays/camera.cpp +1 -1
- data/.doc/ext/rays/color.cpp +2 -2
- data/.doc/ext/rays/color_space.cpp +3 -3
- data/.doc/ext/rays/defs.cpp +4 -4
- data/.doc/ext/rays/font.cpp +4 -3
- data/.doc/ext/rays/image.cpp +32 -18
- data/.doc/ext/rays/matrix.cpp +6 -6
- data/.doc/ext/rays/painter.cpp +1 -1
- data/.doc/ext/rays/point.cpp +10 -6
- data/.doc/ext/rays/polygon.cpp +11 -9
- data/.doc/ext/rays/polyline.cpp +6 -4
- data/.doc/ext/rays/rays.cpp +25 -15
- data/.doc/ext/rays/shader.cpp +3 -3
- data/.github/workflows/release-gem.yml +1 -1
- data/.github/workflows/test.yml +3 -0
- data/ChangeLog.md +11 -0
- data/Gemfile.lock +1 -1
- data/LICENSE +1 -1
- data/Rakefile +17 -3
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +99 -32
- data/ext/rays/bounds.cpp +16 -12
- data/ext/rays/camera.cpp +1 -1
- data/ext/rays/color.cpp +2 -2
- data/ext/rays/color_space.cpp +3 -3
- data/ext/rays/defs.cpp +4 -4
- data/ext/rays/defs.h +2 -0
- data/ext/rays/extconf.rb +4 -2
- data/ext/rays/font.cpp +4 -3
- data/ext/rays/image.cpp +34 -18
- data/ext/rays/matrix.cpp +6 -6
- data/ext/rays/painter.cpp +1 -1
- data/ext/rays/point.cpp +10 -6
- data/ext/rays/polygon.cpp +11 -9
- data/ext/rays/polyline.cpp +6 -4
- data/ext/rays/rays.cpp +25 -15
- data/ext/rays/shader.cpp +3 -3
- data/include/rays/defs.h +7 -0
- data/include/rays/image.h +8 -2
- data/include/rays/ruby/bitmap.h +2 -2
- data/include/rays/ruby/bounds.h +2 -2
- data/include/rays/ruby/camera.h +2 -2
- data/include/rays/ruby/color.h +2 -2
- data/include/rays/ruby/color_space.h +2 -2
- data/include/rays/ruby/exception.h +3 -3
- data/include/rays/ruby/font.h +2 -2
- data/include/rays/ruby/image.h +2 -2
- data/include/rays/ruby/matrix.h +2 -2
- data/include/rays/ruby/painter.h +2 -2
- data/include/rays/ruby/point.h +2 -2
- data/include/rays/ruby/polygon.h +2 -2
- data/include/rays/ruby/polyline.h +2 -2
- data/include/rays/ruby/rays.h +6 -6
- data/include/rays/ruby/shader.h +2 -2
- data/lib/rays/bitmap.rb +7 -0
- data/lib/rays/extension.rb +4 -0
- data/lib/rays/image.rb +4 -0
- data/rays.gemspec +2 -2
- data/src/bounds.cpp +6 -2
- data/src/color.cpp +12 -4
- data/src/coord.h +2 -2
- data/src/font.cpp +1 -0
- data/src/image.cpp +32 -4
- data/src/ios/bitmap.mm +40 -33
- data/src/ios/font.mm +6 -1
- data/src/ios/rays.mm +2 -2
- data/src/matrix.h +1 -1
- data/src/opengl.h +1 -2
- data/src/osx/bitmap.mm +40 -33
- data/src/osx/font.mm +6 -1
- data/src/osx/rays.mm +2 -2
- data/src/painter.cpp +4 -1
- data/src/point.cpp +15 -3
- data/src/polygon.cpp +3 -5
- data/src/render_buffer.cpp +11 -3
- data/src/shader.cpp +3 -0
- data/src/shader_program.cpp +19 -9
- data/src/shader_source.cpp +5 -1
- data/src/texture.cpp +33 -11
- data/src/texture.h +6 -2
- data/src/win32/bitmap.cpp +178 -66
- data/src/win32/camera.cpp +119 -0
- data/src/win32/font.cpp +181 -40
- data/src/win32/gdi.h +1 -1
- data/src/win32/opengl.cpp +127 -0
- data/src/win32/rays.cpp +16 -9
- data/test/helper.rb +2 -0
- data/test/test_bitmap.rb +3 -1
- data/test/test_image.rb +8 -14
- data/test/test_painter.rb +4 -4
- data/test/test_painter_shape.rb +6 -5
- metadata +8 -7
- data/src/win32/font.h +0 -24
data/src/osx/bitmap.mm
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
#import "bitmap.h"
|
3
3
|
|
4
4
|
|
5
|
-
#include <assert.h>
|
6
5
|
#import <Cocoa/Cocoa.h>
|
7
6
|
#include "rays/exception.h"
|
8
7
|
#include "../color_space.h"
|
@@ -60,7 +59,7 @@ namespace Rays
|
|
60
59
|
|
61
60
|
ColorSpace color_space;
|
62
61
|
|
63
|
-
void* pixels
|
62
|
+
void* pixels = NULL;
|
64
63
|
|
65
64
|
CGContextRef context = NULL;
|
66
65
|
|
@@ -122,37 +121,44 @@ namespace Rays
|
|
122
121
|
|
123
122
|
static void
|
124
123
|
setup_bitmap (
|
125
|
-
Bitmap*
|
124
|
+
Bitmap* bitmap,
|
126
125
|
int w, int h, const ColorSpace& cs,
|
127
|
-
const void*
|
126
|
+
const void* pixels = NULL, bool clear_pixels = true)
|
128
127
|
{
|
129
|
-
if (
|
128
|
+
if (w <= 0)
|
130
129
|
argument_error(__FILE__, __LINE__);
|
130
|
+
if (h <= 0)
|
131
|
+
argument_error(__FILE__, __LINE__);
|
132
|
+
if (!cs)
|
133
|
+
argument_error(__FILE__, __LINE__);
|
134
|
+
|
135
|
+
Bitmap::Data* self = bitmap->self.get();
|
131
136
|
|
132
|
-
|
137
|
+
self->clear();
|
133
138
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
139
|
+
self->width = w;
|
140
|
+
self->height = h;
|
141
|
+
self->color_space = cs;
|
142
|
+
self->modified = true;
|
138
143
|
|
139
144
|
size_t size = w * h * cs.Bpp();
|
140
|
-
|
145
|
+
self->pixels = new uchar[size];
|
141
146
|
|
142
|
-
if (
|
143
|
-
memcpy(
|
147
|
+
if (pixels)
|
148
|
+
memcpy(self->pixels, pixels, size);
|
144
149
|
else if (clear_pixels)
|
145
|
-
memset(
|
150
|
+
memset(self->pixels, 0, size);
|
146
151
|
}
|
147
152
|
|
148
|
-
|
149
|
-
|
153
|
+
Bitmap
|
154
|
+
Bitmap_from (const Texture& tex)
|
150
155
|
{
|
151
|
-
if (!
|
156
|
+
if (!tex)
|
152
157
|
argument_error(__FILE__, __LINE__);
|
153
158
|
|
159
|
+
Bitmap bmp;
|
154
160
|
setup_bitmap(
|
155
|
-
|
161
|
+
&bmp, tex.width(), tex.height(), tex.color_space(), NULL, false);
|
156
162
|
|
157
163
|
GLenum format, type;
|
158
164
|
ColorSpace_get_gl_format_and_type(&format, &type, tex.color_space());
|
@@ -160,18 +166,12 @@ namespace Rays
|
|
160
166
|
FrameBuffer fb(tex);
|
161
167
|
FrameBufferBinder binder(fb.id());
|
162
168
|
|
163
|
-
for (int y = 0; y <
|
169
|
+
for (int y = 0; y < bmp.height(); ++y)
|
164
170
|
{
|
165
|
-
GLvoid* ptr = (GLvoid*)
|
166
|
-
glReadPixels(0, y,
|
171
|
+
GLvoid* ptr = (GLvoid*) bmp.at<uchar>(0, y);
|
172
|
+
glReadPixels(0, y, bmp.width(), 1, format, type, ptr);
|
167
173
|
}
|
168
|
-
}
|
169
174
|
|
170
|
-
Bitmap
|
171
|
-
Bitmap_from (const Texture& texture)
|
172
|
-
{
|
173
|
-
Bitmap bmp;
|
174
|
-
setup_bitmap(&bmp, texture);
|
175
175
|
return bmp;
|
176
176
|
}
|
177
177
|
|
@@ -182,7 +182,9 @@ namespace Rays
|
|
182
182
|
{
|
183
183
|
if (width == 0 || height == 0) return;
|
184
184
|
|
185
|
-
if (!bitmap
|
185
|
+
if (!bitmap)
|
186
|
+
argument_error(__FILE__, __LINE__);
|
187
|
+
if (!image)
|
186
188
|
argument_error(__FILE__, __LINE__);
|
187
189
|
|
188
190
|
CGContextRef context = bitmap->self->get_context();
|
@@ -200,21 +202,24 @@ namespace Rays
|
|
200
202
|
Bitmap_draw_string (
|
201
203
|
Bitmap* bitmap, const RawFont& font, const char* str, coord x, coord y)
|
202
204
|
{
|
203
|
-
if (!bitmap
|
205
|
+
if (!bitmap)
|
206
|
+
argument_error(__FILE__, __LINE__);
|
207
|
+
if (!*bitmap)
|
208
|
+
argument_error(__FILE__, __LINE__);
|
209
|
+
if (!font)
|
210
|
+
argument_error(__FILE__, __LINE__);
|
211
|
+
if (!str)
|
204
212
|
argument_error(__FILE__, __LINE__);
|
205
213
|
|
206
214
|
if (*str == '\0') return;
|
207
215
|
|
208
216
|
font.draw_string(bitmap->self->get_context(), bitmap->height(), str, x, y);
|
209
|
-
|
210
217
|
Bitmap_set_modified(bitmap);
|
211
218
|
}
|
212
219
|
|
213
220
|
void
|
214
221
|
Bitmap_set_modified (Bitmap* bitmap, bool modified)
|
215
222
|
{
|
216
|
-
assert(bitmap);
|
217
|
-
|
218
223
|
bitmap->self->modified = modified;
|
219
224
|
}
|
220
225
|
|
@@ -267,7 +272,9 @@ namespace Rays
|
|
267
272
|
Bitmap
|
268
273
|
Bitmap_load (const char* path_)
|
269
274
|
{
|
270
|
-
if (!path_
|
275
|
+
if (!path_)
|
276
|
+
argument_error(__FILE__, __LINE__);
|
277
|
+
if (path_[0] == '\0')
|
271
278
|
argument_error(__FILE__, __LINE__);
|
272
279
|
|
273
280
|
NSString* path = [NSString stringWithUTF8String: path_];
|
data/src/osx/font.mm
CHANGED
@@ -154,11 +154,16 @@ namespace Rays
|
|
154
154
|
{
|
155
155
|
CGContextRef context = (CGContextRef) context_;
|
156
156
|
|
157
|
-
if (
|
157
|
+
if (!context)
|
158
|
+
argument_error(__FILE__, __LINE__);
|
159
|
+
if (!str)
|
158
160
|
argument_error(__FILE__, __LINE__);
|
159
161
|
|
160
162
|
if (*str == '\0') return;
|
161
163
|
|
164
|
+
if (!*this)
|
165
|
+
invalid_state_error(__FILE__, __LINE__);
|
166
|
+
|
162
167
|
CTLinePtr line = make_line(self->font, str);
|
163
168
|
if (!line)
|
164
169
|
rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
|
data/src/osx/rays.mm
CHANGED
@@ -25,7 +25,7 @@ namespace Rays
|
|
25
25
|
init ()
|
26
26
|
{
|
27
27
|
if (global::pool)
|
28
|
-
rays_error(__FILE__, __LINE__, "
|
28
|
+
rays_error(__FILE__, __LINE__, "already initialized.");
|
29
29
|
|
30
30
|
global::pool = [[NSAutoreleasePool alloc] init];
|
31
31
|
|
@@ -36,7 +36,7 @@ namespace Rays
|
|
36
36
|
fin ()
|
37
37
|
{
|
38
38
|
if (!global::pool)
|
39
|
-
rays_error(__FILE__, __LINE__, "
|
39
|
+
rays_error(__FILE__, __LINE__, "not initialized.");
|
40
40
|
|
41
41
|
OpenGL_fin();
|
42
42
|
|
data/src/painter.cpp
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
#include <math.h>
|
5
|
+
#include <string.h>
|
5
6
|
#include <assert.h>
|
6
7
|
#include <memory>
|
7
8
|
#include <vector>
|
@@ -331,7 +332,9 @@ namespace Rays
|
|
331
332
|
const TextureInfo* texinfo = NULL,
|
332
333
|
const Shader* shader = NULL)
|
333
334
|
{
|
334
|
-
if (!points
|
335
|
+
if (!points)
|
336
|
+
argument_error(__FILE__, __LINE__);
|
337
|
+
if (npoints <= 0)
|
335
338
|
argument_error(__FILE__, __LINE__);
|
336
339
|
|
337
340
|
if (!painting)
|
data/src/point.cpp
CHANGED
@@ -159,7 +159,11 @@ namespace Rays
|
|
159
159
|
Point&
|
160
160
|
Point::operator /= (const This& rhs)
|
161
161
|
{
|
162
|
-
if (rhs.x == 0
|
162
|
+
if (rhs.x == 0)
|
163
|
+
argument_error(__FILE__, __LINE__);
|
164
|
+
if (rhs.y == 0)
|
165
|
+
argument_error(__FILE__, __LINE__);
|
166
|
+
if (rhs.z == 0)
|
163
167
|
argument_error(__FILE__, __LINE__);
|
164
168
|
|
165
169
|
to_glm(*this) /= to_glm(rhs);
|
@@ -235,7 +239,11 @@ namespace Rays
|
|
235
239
|
Point
|
236
240
|
operator / (coord lhs, const Point& rhs)
|
237
241
|
{
|
238
|
-
if (rhs.x == 0
|
242
|
+
if (rhs.x == 0)
|
243
|
+
argument_error(__FILE__, __LINE__);
|
244
|
+
if (rhs.y == 0)
|
245
|
+
argument_error(__FILE__, __LINE__);
|
246
|
+
if (rhs.z == 0)
|
239
247
|
argument_error(__FILE__, __LINE__);
|
240
248
|
|
241
249
|
return to_rays<Point>(lhs / to_glm(rhs));
|
@@ -253,7 +261,11 @@ namespace Rays
|
|
253
261
|
Point
|
254
262
|
operator / (const Point& lhs, const Point& rhs)
|
255
263
|
{
|
256
|
-
if (rhs.x == 0
|
264
|
+
if (rhs.x == 0)
|
265
|
+
argument_error(__FILE__, __LINE__);
|
266
|
+
if (rhs.y == 0)
|
267
|
+
argument_error(__FILE__, __LINE__);
|
268
|
+
if (rhs.z == 0)
|
257
269
|
argument_error(__FILE__, __LINE__);
|
258
270
|
|
259
271
|
return to_rays<Point>(to_glm(lhs) / to_glm(rhs));
|
data/src/polygon.cpp
CHANGED
@@ -70,12 +70,10 @@ namespace Rays
|
|
70
70
|
if (!points_)
|
71
71
|
argument_error(__FILE__, __LINE__);
|
72
72
|
|
73
|
-
if (
|
74
|
-
|
75
|
-
|
76
|
-
{
|
73
|
+
if (!points.empty() && !colors_ != !pcolors)
|
74
|
+
argument_error(__FILE__, __LINE__);
|
75
|
+
if (!points.empty() && !texcoords_ != !ptexcoords)
|
77
76
|
argument_error(__FILE__, __LINE__);
|
78
|
-
}
|
79
77
|
|
80
78
|
segments.emplace_back(points.size(), 0, polyline.hole());
|
81
79
|
points.insert(points.end(), points_, points_ + polyline.size());
|
data/src/render_buffer.cpp
CHANGED
@@ -25,16 +25,24 @@ namespace Rays
|
|
25
25
|
|
26
26
|
void create (int width_, int height_)
|
27
27
|
{
|
28
|
-
if (width_
|
28
|
+
if (width_ <= 0)
|
29
|
+
argument_error(__FILE__, __LINE__);
|
30
|
+
if (height_ <= 0)
|
29
31
|
argument_error(__FILE__, __LINE__);
|
30
32
|
|
31
33
|
if (is_valid())
|
32
34
|
{
|
33
|
-
if (width
|
35
|
+
if (width != width_)
|
36
|
+
{
|
37
|
+
argument_error(__FILE__, __LINE__,
|
38
|
+
"RenderBuffer is already created and "
|
39
|
+
"width parameters is not same as current width.");
|
40
|
+
}
|
41
|
+
if (height != height_)
|
34
42
|
{
|
35
43
|
argument_error(__FILE__, __LINE__,
|
36
44
|
"RenderBuffer is already created and "
|
37
|
-
"
|
45
|
+
"height parameters is not same as current height.");
|
38
46
|
}
|
39
47
|
return;
|
40
48
|
}
|
data/src/shader.cpp
CHANGED
@@ -156,6 +156,9 @@ namespace Rays
|
|
156
156
|
// restore premultiplied rgb values
|
157
157
|
" vec3 rgb__ = col__.a != 0.0 ? col__.rgb / col__.a : col__.rgb;\n"
|
158
158
|
" gl_FragColor = " + V_COLOR + " * vec4(rgb__, col__.a);\n"
|
159
|
+
#elif defined(WIN32)
|
160
|
+
" float a__ = (col__.r + col__.g + col__.b) / 3.0;\n"
|
161
|
+
" gl_FragColor = " + V_COLOR + " * vec4(1.0, 1.0, 1.0, a__);\n"
|
159
162
|
#else
|
160
163
|
" gl_FragColor = " + V_COLOR + " * col__;\n"
|
161
164
|
#endif
|
data/src/shader_program.cpp
CHANGED
@@ -99,42 +99,50 @@ namespace Rays
|
|
99
99
|
};// UniformValueT
|
100
100
|
|
101
101
|
|
102
|
-
template <> void
|
102
|
+
template <> void
|
103
|
+
UniformValueT<int, 1>::apply_value (GLint location) const
|
103
104
|
{
|
104
105
|
glUniform1iv(location, 1, array);
|
105
106
|
}
|
106
107
|
|
107
|
-
template <> void
|
108
|
+
template <> void
|
109
|
+
UniformValueT<int, 2>::apply_value (GLint location) const
|
108
110
|
{
|
109
111
|
glUniform2iv(location, 1, array);
|
110
112
|
}
|
111
113
|
|
112
|
-
template <> void
|
114
|
+
template <> void
|
115
|
+
UniformValueT<int, 3>::apply_value (GLint location) const
|
113
116
|
{
|
114
117
|
glUniform3iv(location, 1, array);
|
115
118
|
}
|
116
119
|
|
117
|
-
template <> void
|
120
|
+
template <> void
|
121
|
+
UniformValueT<int, 4>::apply_value (GLint location) const
|
118
122
|
{
|
119
123
|
glUniform4iv(location, 1, array);
|
120
124
|
}
|
121
125
|
|
122
|
-
template <> void
|
126
|
+
template <> void
|
127
|
+
UniformValueT<float, 1>::apply_value (GLint location) const
|
123
128
|
{
|
124
129
|
glUniform1fv(location, 1, array);
|
125
130
|
}
|
126
131
|
|
127
|
-
template <> void
|
132
|
+
template <> void
|
133
|
+
UniformValueT<float, 2>::apply_value (GLint location) const
|
128
134
|
{
|
129
135
|
glUniform2fv(location, 1, array);
|
130
136
|
}
|
131
137
|
|
132
|
-
template <> void
|
138
|
+
template <> void
|
139
|
+
UniformValueT<float, 3>::apply_value (GLint location) const
|
133
140
|
{
|
134
141
|
glUniform3fv(location, 1, array);
|
135
142
|
}
|
136
143
|
|
137
|
-
template <> void
|
144
|
+
template <> void
|
145
|
+
UniformValueT<float, 4>::apply_value (GLint location) const
|
138
146
|
{
|
139
147
|
glUniform4fv(location, 1, array);
|
140
148
|
}
|
@@ -191,7 +199,9 @@ namespace Rays
|
|
191
199
|
|
192
200
|
Uniform (const char* name, const UniformValue* value)
|
193
201
|
{
|
194
|
-
if (!name
|
202
|
+
if (!name)
|
203
|
+
argument_error(__FILE__, __LINE__);
|
204
|
+
if (name[0] == '\0')
|
195
205
|
argument_error(__FILE__, __LINE__);
|
196
206
|
|
197
207
|
reset(value);
|
data/src/shader_source.cpp
CHANGED
@@ -29,7 +29,11 @@ namespace Rays
|
|
29
29
|
|
30
30
|
void compile (GLenum type_, const char* source_)
|
31
31
|
{
|
32
|
-
if (!is_valid_type(type_)
|
32
|
+
if (!is_valid_type(type_))
|
33
|
+
argument_error(__FILE__, __LINE__);
|
34
|
+
if (!source_)
|
35
|
+
argument_error(__FILE__, __LINE__);
|
36
|
+
if (!*source_)
|
33
37
|
argument_error(__FILE__, __LINE__);
|
34
38
|
|
35
39
|
if (is_valid())
|
data/src/texture.cpp
CHANGED
@@ -23,7 +23,7 @@ namespace Rays
|
|
23
23
|
|
24
24
|
ColorSpace color_space;
|
25
25
|
|
26
|
-
bool modified;
|
26
|
+
bool smooth, modified;
|
27
27
|
|
28
28
|
Data ()
|
29
29
|
{
|
@@ -44,6 +44,7 @@ namespace Rays
|
|
44
44
|
width_pow2 =
|
45
45
|
height_pow2 = 0;
|
46
46
|
color_space = COLORSPACE_UNKNOWN;
|
47
|
+
smooth = false;
|
47
48
|
modified = false;
|
48
49
|
}
|
49
50
|
|
@@ -110,7 +111,13 @@ namespace Rays
|
|
110
111
|
size_t width,
|
111
112
|
uchar* dest, size_t dest_stride, const uchar* src, size_t src_stride)
|
112
113
|
{
|
113
|
-
if (!dest
|
114
|
+
if (!dest)
|
115
|
+
argument_error(__FILE__, __LINE__);
|
116
|
+
if (!src)
|
117
|
+
argument_error(__FILE__, __LINE__);
|
118
|
+
if (dest_stride <= 0)
|
119
|
+
argument_error(__FILE__, __LINE__);
|
120
|
+
if ( src_stride <= 0)
|
114
121
|
argument_error(__FILE__, __LINE__);
|
115
122
|
|
116
123
|
while (width--)
|
@@ -171,7 +178,8 @@ namespace Rays
|
|
171
178
|
|
172
179
|
static void
|
173
180
|
setup_texture (
|
174
|
-
Texture::Data* self,
|
181
|
+
Texture::Data* self,
|
182
|
+
int width, int height, const ColorSpace& cs, bool smooth = false,
|
175
183
|
const Bitmap* bitmap = NULL, bool npot = false)
|
176
184
|
{
|
177
185
|
assert(self && !self->has_id());
|
@@ -184,7 +192,8 @@ namespace Rays
|
|
184
192
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
185
193
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
186
194
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
187
|
-
glTexParameteri(
|
195
|
+
glTexParameteri(
|
196
|
+
GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, smooth ? GL_LINEAR : GL_NEAREST);
|
188
197
|
|
189
198
|
GLenum format, type;
|
190
199
|
ColorSpace_get_gl_format_and_type(&format, &type, cs);
|
@@ -216,6 +225,7 @@ namespace Rays
|
|
216
225
|
self->width = width;
|
217
226
|
self->height = height;
|
218
227
|
self->color_space = cs;
|
228
|
+
self->smooth = smooth;
|
219
229
|
self->modified = true;
|
220
230
|
}
|
221
231
|
|
@@ -224,21 +234,25 @@ namespace Rays
|
|
224
234
|
{
|
225
235
|
}
|
226
236
|
|
227
|
-
Texture::Texture (int width, int height, const ColorSpace& cs)
|
237
|
+
Texture::Texture (int width, int height, const ColorSpace& cs, bool smooth)
|
228
238
|
{
|
229
|
-
if (width
|
239
|
+
if (width <= 0)
|
240
|
+
argument_error(__FILE__, __LINE__);
|
241
|
+
if (height <= 0)
|
242
|
+
argument_error(__FILE__, __LINE__);
|
243
|
+
if (!cs)
|
230
244
|
argument_error(__FILE__, __LINE__);
|
231
245
|
|
232
|
-
setup_texture(self.get(), width, height, cs);
|
246
|
+
setup_texture(self.get(), width, height, cs, smooth);
|
233
247
|
}
|
234
248
|
|
235
|
-
Texture::Texture (const Bitmap& bitmap)
|
249
|
+
Texture::Texture (const Bitmap& bitmap, bool smooth)
|
236
250
|
{
|
237
251
|
if (!bitmap)
|
238
252
|
argument_error(__FILE__, __LINE__);
|
239
253
|
|
240
254
|
setup_texture(
|
241
|
-
self.get(), bitmap.width(), bitmap.height(), bitmap.color_space(),
|
255
|
+
self.get(), bitmap.width(), bitmap.height(), bitmap.color_space(), smooth,
|
242
256
|
&bitmap);
|
243
257
|
}
|
244
258
|
|
@@ -249,8 +263,10 @@ namespace Rays
|
|
249
263
|
argument_error(__FILE__, __LINE__);
|
250
264
|
|
251
265
|
int w = bitmap.width(), h = bitmap.height();
|
252
|
-
if (w != width()
|
253
|
-
argument_error(__FILE__, __LINE__, "the
|
266
|
+
if (w != width())
|
267
|
+
argument_error(__FILE__, __LINE__, "the width of bitmap does not match");
|
268
|
+
if (h != height())
|
269
|
+
argument_error(__FILE__, __LINE__, "the height of bitmap does not match");
|
254
270
|
|
255
271
|
GLenum format, type;
|
256
272
|
ColorSpace_get_gl_format_and_type(&format, &type, bitmap.color_space());
|
@@ -297,6 +313,12 @@ namespace Rays
|
|
297
313
|
return self->color_space;
|
298
314
|
}
|
299
315
|
|
316
|
+
bool
|
317
|
+
Texture::smooth () const
|
318
|
+
{
|
319
|
+
return self->smooth;
|
320
|
+
}
|
321
|
+
|
300
322
|
GLuint
|
301
323
|
Texture::id () const
|
302
324
|
{
|
data/src/texture.h
CHANGED
@@ -24,9 +24,11 @@ namespace Rays
|
|
24
24
|
|
25
25
|
Texture ();
|
26
26
|
|
27
|
-
Texture (
|
27
|
+
Texture (
|
28
|
+
int width, int height, const ColorSpace& cs = RGBA,
|
29
|
+
bool smooth = false);
|
28
30
|
|
29
|
-
Texture (const Bitmap& bitmap);
|
31
|
+
Texture (const Bitmap& bitmap, bool smooth = false);
|
30
32
|
|
31
33
|
Texture& operator = (const Bitmap& bitmap);
|
32
34
|
|
@@ -42,6 +44,8 @@ namespace Rays
|
|
42
44
|
|
43
45
|
const ColorSpace& color_space () const;
|
44
46
|
|
47
|
+
bool smooth () const;
|
48
|
+
|
45
49
|
GLuint id () const;
|
46
50
|
|
47
51
|
void set_modified (bool modified = true);
|