rays 0.1.12 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/camera.cpp +171 -0
- data/.doc/ext/rays/color.cpp +223 -45
- data/.doc/ext/rays/color_space.cpp +146 -46
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +69 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +14 -8
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +187 -292
- data/.doc/ext/rays/point.cpp +96 -77
- data/.doc/ext/rays/polygon.cpp +313 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +167 -0
- data/.doc/ext/rays/rays.cpp +103 -12
- data/.doc/ext/rays/shader.cpp +83 -9
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +24 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +23 -81
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/camera.cpp +186 -0
- data/ext/rays/color.cpp +231 -51
- data/ext/rays/color_space.cpp +149 -47
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +2 -3
- data/ext/rays/font.cpp +74 -24
- data/ext/rays/image.cpp +28 -40
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +14 -8
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +203 -298
- data/ext/rays/point.cpp +105 -81
- data/ext/rays/polygon.cpp +329 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +176 -0
- data/ext/rays/rays.cpp +103 -13
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/camera.h +74 -0
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +15 -10
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +36 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +12 -18
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +89 -93
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +198 -0
- data/include/rays/polyline.h +71 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/camera.h +41 -0
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/rays.h +8 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +7 -2
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/camera.rb +24 -0
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +3 -7
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +78 -93
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +58 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +52 -34
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +172 -98
- data/src/image.h +25 -0
- data/src/ios/bitmap.h +23 -0
- data/src/ios/bitmap.mm +133 -110
- data/src/ios/camera.mm +510 -0
- data/src/ios/font.mm +50 -62
- data/src/ios/helper.h +4 -4
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.h +23 -0
- data/src/osx/bitmap.mm +133 -110
- data/src/osx/camera.mm +451 -0
- data/src/osx/font.mm +49 -62
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +845 -671
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1266 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +160 -0
- data/src/polyline.h +69 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_font.rb +5 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +157 -51
- data/test/test_painter_shape.rb +102 -0
- data/test/test_point.rb +29 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +171 -0
- data/test/test_shader.rb +9 -9
- metadata +102 -70
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
data/src/font.h
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_SRC_FONT_H__
|
4
|
+
#define __RAYS_SRC_FONT_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rays/defs.h>
|
8
|
+
#include <rays/font.h>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Rays
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
class RawFont
|
16
|
+
{
|
17
|
+
|
18
|
+
public:
|
19
|
+
|
20
|
+
RawFont ();
|
21
|
+
|
22
|
+
RawFont (const char* name, coord size = 0);
|
23
|
+
|
24
|
+
~RawFont ();
|
25
|
+
|
26
|
+
void draw_string (
|
27
|
+
void* context, coord context_height,
|
28
|
+
const char* str, coord x, coord y) const;
|
29
|
+
|
30
|
+
String name () const;
|
31
|
+
|
32
|
+
coord size () const;
|
33
|
+
|
34
|
+
coord get_width (const char* str) const;
|
35
|
+
|
36
|
+
coord get_height (
|
37
|
+
coord* ascent = NULL,
|
38
|
+
coord* descent = NULL,
|
39
|
+
coord* leading = NULL) const;
|
40
|
+
|
41
|
+
operator bool () const;
|
42
|
+
|
43
|
+
bool operator ! () const;
|
44
|
+
|
45
|
+
struct Data;
|
46
|
+
|
47
|
+
Xot::PSharedImpl<Data> self;
|
48
|
+
|
49
|
+
};// RawFont
|
50
|
+
|
51
|
+
|
52
|
+
const RawFont& Font_get_raw (const Font& font, float pixel_density);
|
53
|
+
|
54
|
+
coord Font_get_width (const Font& font, float pixel_density, const char* str);
|
55
|
+
|
56
|
+
coord Font_get_height (
|
57
|
+
const Font& font, float pixel_density,
|
58
|
+
coord* ascent = NULL, coord* descent = NULL, coord* leading = NULL);
|
59
|
+
|
60
|
+
|
61
|
+
}// Rays
|
62
|
+
|
63
|
+
|
64
|
+
#endif//EOH
|
data/src/frame_buffer.cpp
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
|
4
4
|
#include <vector>
|
5
5
|
#include "rays/exception.h"
|
6
|
-
#include "rays/
|
7
|
-
#include "
|
6
|
+
#include "rays/debug.h"
|
7
|
+
#include "texture.h"
|
8
8
|
#include "render_buffer.h"
|
9
9
|
|
10
10
|
|
@@ -15,17 +15,12 @@ namespace Rays
|
|
15
15
|
struct FrameBuffer::Data
|
16
16
|
{
|
17
17
|
|
18
|
-
int id;
|
18
|
+
int id = -1;
|
19
19
|
|
20
20
|
Texture texture;
|
21
21
|
|
22
22
|
RenderBuffer render_buffer;
|
23
23
|
|
24
|
-
Data ()
|
25
|
-
: id(-1)
|
26
|
-
{
|
27
|
-
}
|
28
|
-
|
29
24
|
~Data ()
|
30
25
|
{
|
31
26
|
clear();
|
@@ -37,7 +32,7 @@ namespace Rays
|
|
37
32
|
|
38
33
|
GLuint id_ = 0;
|
39
34
|
glGenFramebuffers(1, &id_);
|
40
|
-
|
35
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
41
36
|
|
42
37
|
id = id_;
|
43
38
|
}
|
@@ -51,7 +46,7 @@ namespace Rays
|
|
51
46
|
{
|
52
47
|
GLuint id_ = id;
|
53
48
|
glDeleteFramebuffers(1, &id_);
|
54
|
-
|
49
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
55
50
|
}
|
56
51
|
|
57
52
|
id = -1;
|
@@ -83,21 +78,17 @@ namespace Rays
|
|
83
78
|
{
|
84
79
|
switch (status)
|
85
80
|
{
|
81
|
+
case GL_FRAMEBUFFER_UNSUPPORTED: return "GL_FRAMEBUFFER_UNSUPPORTED";
|
82
|
+
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
|
83
|
+
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
|
84
|
+
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: return "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
|
86
85
|
#ifdef IOS
|
87
|
-
case
|
88
|
-
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES: return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES";
|
89
|
-
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES: return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES";
|
90
|
-
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES: return "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES";
|
91
|
-
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES: return "GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES";
|
86
|
+
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: return "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
|
92
87
|
#else
|
93
|
-
case GL_FRAMEBUFFER_UNDEFINED:
|
94
|
-
case
|
95
|
-
case
|
96
|
-
case
|
97
|
-
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: return "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER";
|
98
|
-
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: return "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER";
|
99
|
-
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: return "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
|
100
|
-
//case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: return "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS";
|
88
|
+
case GL_FRAMEBUFFER_UNDEFINED: return "GL_FRAMEBUFFER_UNDEFINED";
|
89
|
+
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: return "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER";
|
90
|
+
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: return "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER";
|
91
|
+
//case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: return "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS";
|
101
92
|
#endif
|
102
93
|
}
|
103
94
|
return "UNKNOWN STATUS";
|
@@ -114,14 +105,13 @@ namespace Rays
|
|
114
105
|
FrameBufferBinder binder(id());
|
115
106
|
|
116
107
|
glFramebufferTexture2D(
|
117
|
-
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
118
|
-
|
119
|
-
check_error(__FILE__, __LINE__);
|
108
|
+
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id(), 0);
|
109
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
120
110
|
|
121
111
|
self->texture = texture;
|
122
112
|
|
123
113
|
#if 0
|
124
|
-
int w = texture.
|
114
|
+
int w = texture.reserved_width(), h = texture.reserved_height();
|
125
115
|
if (
|
126
116
|
w != self->render_buffer.width() ||
|
127
117
|
h != self->render_buffer.height())
|
@@ -131,7 +121,7 @@ namespace Rays
|
|
131
121
|
glFramebufferRenderbuffer(
|
132
122
|
GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
133
123
|
GL_RENDERBUFFER, rb.id());
|
134
|
-
|
124
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
135
125
|
|
136
126
|
self->render_buffer = rb;
|
137
127
|
}
|
@@ -185,7 +175,9 @@ namespace Rays
|
|
185
175
|
return false;
|
186
176
|
|
187
177
|
const RenderBuffer& r = self->render_buffer;
|
188
|
-
|
178
|
+
int w = t.reserved_width();
|
179
|
+
int h = t.reserved_height();
|
180
|
+
if (r && (r.width() != w || r.height() != h))
|
189
181
|
return false;
|
190
182
|
|
191
183
|
return true;
|
@@ -201,12 +193,12 @@ namespace Rays
|
|
201
193
|
FrameBufferBinder::FrameBufferBinder (GLuint id)
|
202
194
|
: id(id)
|
203
195
|
{
|
204
|
-
|
196
|
+
FrameBuffer_bind(id);
|
205
197
|
}
|
206
198
|
|
207
199
|
FrameBufferBinder::~FrameBufferBinder ()
|
208
200
|
{
|
209
|
-
|
201
|
+
FrameBuffer_unbind();
|
210
202
|
}
|
211
203
|
|
212
204
|
GLuint
|
@@ -216,59 +208,33 @@ namespace Rays
|
|
216
208
|
}
|
217
209
|
|
218
210
|
|
219
|
-
|
220
|
-
{
|
221
|
-
|
222
|
-
GLuint draw, read;
|
223
|
-
|
224
|
-
FrameBufferID ()
|
225
|
-
: draw(0), read(0)
|
226
|
-
{
|
227
|
-
}
|
228
|
-
|
229
|
-
FrameBufferID (GLuint draw, GLuint read)
|
230
|
-
: draw(draw), read(read)
|
231
|
-
{
|
232
|
-
}
|
233
|
-
|
234
|
-
};// FrameBufferID
|
211
|
+
static std::vector<GLuint> frame_buffer_bind_stack;
|
235
212
|
|
236
|
-
static std::vector<FrameBufferID> frame_buffer_bind_stack;
|
237
213
|
|
238
|
-
|
239
|
-
|
240
|
-
bind_frame_buffer (GLuint draw, GLuint read)
|
214
|
+
void
|
215
|
+
FrameBuffer_bind (GLuint id)
|
241
216
|
{
|
242
|
-
|
243
|
-
glGetIntegerv(
|
244
|
-
|
245
|
-
check_error(__FILE__, __LINE__);
|
217
|
+
GLuint current = 0;
|
218
|
+
glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*) ¤t);
|
219
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
246
220
|
|
247
|
-
frame_buffer_bind_stack.push_back(
|
221
|
+
frame_buffer_bind_stack.push_back(current);
|
248
222
|
|
249
|
-
glBindFramebuffer(
|
250
|
-
|
251
|
-
check_error(__FILE__, __LINE__);
|
252
|
-
}
|
253
|
-
|
254
|
-
void
|
255
|
-
bind_frame_buffer (GLuint id)
|
256
|
-
{
|
257
|
-
bind_frame_buffer(id, id);
|
223
|
+
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
224
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
258
225
|
}
|
259
226
|
|
260
227
|
void
|
261
|
-
|
228
|
+
FrameBuffer_unbind ()
|
262
229
|
{
|
263
230
|
if (frame_buffer_bind_stack.empty())
|
264
|
-
rays_error(__FILE__, __LINE__, "frame_buffer_bind_stack
|
231
|
+
rays_error(__FILE__, __LINE__, "frame_buffer_bind_stack underflow.");
|
265
232
|
|
266
|
-
|
233
|
+
GLuint id = frame_buffer_bind_stack.back();
|
267
234
|
frame_buffer_bind_stack.pop_back();
|
268
235
|
|
269
|
-
glBindFramebuffer(
|
270
|
-
|
271
|
-
check_error(__FILE__, __LINE__);
|
236
|
+
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
237
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
272
238
|
}
|
273
239
|
|
274
240
|
|
data/src/frame_buffer.h
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
#include <xot/pimpl.h>
|
8
8
|
#include <rays/defs.h>
|
9
|
-
#include
|
9
|
+
#include "opengl.h"
|
10
10
|
|
11
11
|
|
12
12
|
namespace Rays
|
@@ -45,7 +45,7 @@ namespace Rays
|
|
45
45
|
|
46
46
|
struct Data;
|
47
47
|
|
48
|
-
Xot::
|
48
|
+
Xot::PSharedImpl<Data> self;
|
49
49
|
|
50
50
|
};// FrameBuffer
|
51
51
|
|
@@ -68,9 +68,9 @@ namespace Rays
|
|
68
68
|
};// FrameBufferBinder
|
69
69
|
|
70
70
|
|
71
|
-
void
|
71
|
+
void FrameBuffer_bind (GLuint id);
|
72
72
|
|
73
|
-
void
|
73
|
+
void FrameBuffer_unbind ();
|
74
74
|
|
75
75
|
|
76
76
|
}// Rays
|
data/src/image.cpp
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
#include "
|
1
|
+
#include "image.h"
|
2
2
|
|
3
3
|
|
4
|
+
#include <math.h>
|
5
|
+
#include <assert.h>
|
4
6
|
#include "rays/exception.h"
|
5
|
-
#include "rays/
|
6
|
-
#include "
|
7
|
+
#include "rays/debug.h"
|
8
|
+
#include "opengl.h"
|
9
|
+
#include "bitmap.h"
|
10
|
+
#include "texture.h"
|
7
11
|
|
8
12
|
|
9
13
|
namespace Rays
|
@@ -13,171 +17,241 @@ namespace Rays
|
|
13
17
|
struct Image::Data
|
14
18
|
{
|
15
19
|
|
16
|
-
int width, height;
|
20
|
+
int width = 0, height = 0;
|
17
21
|
|
18
22
|
ColorSpace color_space;
|
19
23
|
|
20
|
-
|
24
|
+
float pixel_density = 1;
|
21
25
|
|
22
26
|
mutable Bitmap bitmap;
|
23
27
|
|
24
28
|
mutable Texture texture;
|
25
29
|
|
26
|
-
Data ()
|
27
|
-
: width(0), height(0), alpha_only(false)
|
28
|
-
{
|
29
|
-
}
|
30
|
-
|
31
30
|
};// Image::Data
|
32
31
|
|
33
32
|
|
34
|
-
|
33
|
+
static void
|
34
|
+
invalidate_texture (Image* image)
|
35
35
|
{
|
36
|
+
image->bitmap();// update bitmap
|
37
|
+
image->self->texture = Texture();
|
36
38
|
}
|
37
39
|
|
38
|
-
|
40
|
+
static void
|
41
|
+
invalidate_texture_for_another_context (Image* image)
|
39
42
|
{
|
40
|
-
|
41
|
-
self->height = height;
|
42
|
-
self->color_space = cs;
|
43
|
-
self->alpha_only = alpha_only;
|
44
|
-
}
|
43
|
+
assert(image);
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
self->width = bitmap.width();
|
49
|
-
self->height = bitmap.height();
|
50
|
-
self->color_space = bitmap.color_space();
|
51
|
-
self->alpha_only = alpha_only;
|
52
|
-
self->bitmap = bitmap;
|
53
|
-
}
|
45
|
+
const Texture& tex = image->self->texture;
|
46
|
+
if (!tex) return;
|
54
47
|
|
55
|
-
|
56
|
-
|
57
|
-
}
|
48
|
+
Context tex_context = tex.context();
|
49
|
+
if (!tex_context) return;
|
58
50
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
return Image(width(), height(), color_space(), alpha_only());
|
63
|
-
}
|
51
|
+
Context current_context = OpenGL_get_context();
|
52
|
+
if (tex_context == current_context)
|
53
|
+
return;
|
64
54
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
Painter p;
|
69
|
-
p.bind(texture());
|
70
|
-
return p;
|
71
|
-
}
|
72
|
-
|
73
|
-
int
|
74
|
-
Image::width () const
|
75
|
-
{
|
76
|
-
return self->width;
|
55
|
+
OpenGL_set_context(tex_context);
|
56
|
+
invalidate_texture(image);
|
57
|
+
OpenGL_set_context(current_context);
|
77
58
|
}
|
78
59
|
|
79
|
-
|
80
|
-
Image
|
60
|
+
static Bitmap&
|
61
|
+
get_bitmap (Image& image)
|
81
62
|
{
|
82
|
-
|
83
|
-
}
|
63
|
+
Image::Data* self = image.self.get();
|
84
64
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
bool
|
92
|
-
Image::alpha_only () const
|
93
|
-
{
|
94
|
-
return self->alpha_only;
|
95
|
-
}
|
65
|
+
if (!image)
|
66
|
+
{
|
67
|
+
assert(!self->bitmap);
|
68
|
+
return self->bitmap;
|
69
|
+
}
|
96
70
|
|
97
|
-
Bitmap&
|
98
|
-
Image::bitmap ()
|
99
|
-
{
|
100
71
|
if (!self->bitmap)
|
101
72
|
{
|
102
73
|
if (self->texture)
|
103
|
-
self->bitmap =
|
74
|
+
self->bitmap = Bitmap_from(self->texture);
|
104
75
|
else
|
105
76
|
self->bitmap = Bitmap(self->width, self->height, self->color_space);
|
106
77
|
}
|
107
|
-
else if (
|
108
|
-
self->
|
78
|
+
else if (
|
79
|
+
self->texture &&
|
80
|
+
self->texture.modified() &&
|
81
|
+
!Bitmap_get_modified(self->bitmap))
|
82
|
+
{
|
83
|
+
self->bitmap = Bitmap_from(self->texture);
|
84
|
+
}
|
109
85
|
|
110
|
-
if (self->bitmap) self->bitmap
|
111
|
-
if (self->texture) self->texture.
|
86
|
+
if (self->bitmap) Bitmap_set_modified(&self->bitmap, false);
|
87
|
+
if (self->texture) self->texture.set_modified(false);
|
112
88
|
|
113
89
|
return self->bitmap;
|
114
90
|
}
|
115
91
|
|
116
|
-
const Bitmap&
|
117
|
-
Image::bitmap () const
|
118
|
-
{
|
119
|
-
return const_cast<This*>(this)->bitmap();
|
120
|
-
}
|
121
|
-
|
122
92
|
Texture&
|
123
|
-
Image
|
93
|
+
Image_get_texture (Image& image)
|
124
94
|
{
|
95
|
+
Image::Data* self = image.self.get();
|
96
|
+
|
97
|
+
if (!image)
|
98
|
+
{
|
99
|
+
assert(!self->texture);
|
100
|
+
return self->texture;
|
101
|
+
}
|
102
|
+
|
103
|
+
invalidate_texture_for_another_context(&image);
|
104
|
+
|
125
105
|
if (!self->texture)
|
126
106
|
{
|
127
107
|
if (self->bitmap)
|
128
|
-
self->texture = Texture(self->bitmap
|
108
|
+
self->texture = Texture(self->bitmap);
|
129
109
|
else
|
130
110
|
{
|
131
|
-
self->texture = Texture(
|
132
|
-
self->width, self->height, self->color_space, self->alpha_only);
|
111
|
+
self->texture = Texture(self->width, self->height, self->color_space);
|
133
112
|
|
134
|
-
Painter p;
|
135
|
-
p.bind(self->texture);
|
113
|
+
Painter p = image.painter();
|
136
114
|
p.begin();
|
137
115
|
p.clear();
|
138
116
|
p.end();
|
139
117
|
}
|
140
118
|
}
|
141
|
-
else if (
|
142
|
-
self->
|
119
|
+
else if (
|
120
|
+
self->bitmap &&
|
121
|
+
Bitmap_get_modified(self->bitmap) &&
|
122
|
+
!self->texture.modified())
|
123
|
+
{
|
124
|
+
self->texture = Texture(self->bitmap);
|
125
|
+
}
|
143
126
|
|
144
|
-
if (self->bitmap) self->bitmap
|
145
|
-
if (self->texture) self->texture.
|
127
|
+
if (self->bitmap) Bitmap_set_modified(&self->bitmap, false);
|
128
|
+
if (self->texture) self->texture.set_modified(false);
|
146
129
|
|
147
130
|
return self->texture;
|
148
131
|
}
|
149
132
|
|
150
133
|
const Texture&
|
151
|
-
Image
|
134
|
+
Image_get_texture (const Image& image)
|
152
135
|
{
|
153
|
-
return const_cast<
|
136
|
+
return Image_get_texture(const_cast<Image&>(image));
|
154
137
|
}
|
155
138
|
|
156
|
-
|
139
|
+
void
|
140
|
+
save_image (const Image& image, const char* path)
|
157
141
|
{
|
158
|
-
|
142
|
+
if (!image)
|
143
|
+
argument_error(__FILE__, __LINE__);
|
144
|
+
|
145
|
+
return Bitmap_save(image.bitmap(), path);
|
159
146
|
}
|
160
147
|
|
161
|
-
|
162
|
-
|
148
|
+
Image
|
149
|
+
load_image (const char* path)
|
150
|
+
{
|
151
|
+
return Image(Bitmap_load(path));
|
152
|
+
}
|
153
|
+
|
154
|
+
|
155
|
+
Image::Image ()
|
163
156
|
{
|
164
|
-
return !operator bool();
|
165
157
|
}
|
166
158
|
|
159
|
+
Image::Image (
|
160
|
+
int width, int height, const ColorSpace& cs, float pixel_density)
|
161
|
+
{
|
162
|
+
if (pixel_density <= 0)
|
163
|
+
argument_error(__FILE__, __LINE__, "invalid pixel_density.");
|
164
|
+
|
165
|
+
coord w = width * pixel_density;
|
166
|
+
coord h = height * pixel_density;
|
167
|
+
if ((w - (int) w) != 0 || (h - (int) h) != 0)
|
168
|
+
argument_error(__FILE__, __LINE__, "invalid size for image.");
|
169
|
+
|
170
|
+
self->width = w;
|
171
|
+
self->height = h;
|
172
|
+
self->color_space = cs;
|
173
|
+
self->pixel_density = pixel_density;
|
174
|
+
}
|
175
|
+
|
176
|
+
Image::Image (const Bitmap& bitmap, float pixel_density)
|
177
|
+
{
|
178
|
+
if (pixel_density <= 0)
|
179
|
+
argument_error(__FILE__, __LINE__, "invalid pixel_density.");
|
180
|
+
|
181
|
+
self->bitmap = bitmap;
|
182
|
+
self->width = bitmap.width();
|
183
|
+
self->height = bitmap.height();
|
184
|
+
self->color_space = bitmap.color_space();
|
185
|
+
self->pixel_density = pixel_density;
|
186
|
+
}
|
187
|
+
|
188
|
+
Image::~Image ()
|
189
|
+
{
|
190
|
+
}
|
167
191
|
|
168
192
|
Image
|
169
|
-
|
193
|
+
Image::dup () const
|
170
194
|
{
|
171
|
-
return Image(
|
195
|
+
return Image(bitmap().dup(), pixel_density());
|
172
196
|
}
|
173
197
|
|
174
|
-
|
175
|
-
|
198
|
+
coord
|
199
|
+
Image::width () const
|
176
200
|
{
|
177
|
-
|
178
|
-
|
201
|
+
return self->width / self->pixel_density;
|
202
|
+
}
|
179
203
|
|
180
|
-
|
204
|
+
coord
|
205
|
+
Image::height () const
|
206
|
+
{
|
207
|
+
return self->height / self->pixel_density;
|
208
|
+
}
|
209
|
+
|
210
|
+
const ColorSpace&
|
211
|
+
Image::color_space () const
|
212
|
+
{
|
213
|
+
return self->color_space;
|
214
|
+
}
|
215
|
+
|
216
|
+
float
|
217
|
+
Image::pixel_density () const
|
218
|
+
{
|
219
|
+
return self->pixel_density;
|
220
|
+
}
|
221
|
+
|
222
|
+
Painter
|
223
|
+
Image::painter ()
|
224
|
+
{
|
225
|
+
Painter p;
|
226
|
+
p.bind(*this);
|
227
|
+
return p;
|
228
|
+
}
|
229
|
+
|
230
|
+
Bitmap&
|
231
|
+
Image::bitmap ()
|
232
|
+
{
|
233
|
+
return get_bitmap(*this);
|
234
|
+
}
|
235
|
+
|
236
|
+
const Bitmap&
|
237
|
+
Image::bitmap () const
|
238
|
+
{
|
239
|
+
return get_bitmap(const_cast<Image&>(*this));
|
240
|
+
}
|
241
|
+
|
242
|
+
Image::operator bool () const
|
243
|
+
{
|
244
|
+
return
|
245
|
+
self->width > 0 &&
|
246
|
+
self->height > 0 &&
|
247
|
+
self->pixel_density > 0 &&
|
248
|
+
self->color_space;
|
249
|
+
}
|
250
|
+
|
251
|
+
bool
|
252
|
+
Image::operator ! () const
|
253
|
+
{
|
254
|
+
return !operator bool();
|
181
255
|
}
|
182
256
|
|
183
257
|
|