sfml3-rb 0.2.2 → 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/.yardopts +9 -0
- data/CHANGELOG.md +67 -16
- data/README.md +123 -32
- data/TODO.md +18 -11
- data/ext/audio/audio_enums.c +58 -20
- data/ext/audio/listener.c +89 -6
- data/ext/audio/music.c +212 -5
- data/ext/audio/sound.c +218 -9
- data/ext/audio/sound_buffer.c +197 -47
- data/ext/audio/sound_buffer_recorder.c +90 -18
- data/ext/audio/sound_recorder.c +188 -58
- data/ext/audio/sound_source_cone.c +127 -33
- data/ext/audio/sound_stream.c +204 -21
- data/ext/core/exceptions.c +10 -8
- data/ext/core/unicode.c +12 -2
- data/ext/ext.c +8 -0
- data/ext/graphics/blend_mode.c +218 -60
- data/ext/graphics/circle.c +300 -16
- data/ext/graphics/color.c +253 -94
- data/ext/graphics/drawable.c +16 -4
- data/ext/graphics/font.c +144 -25
- data/ext/graphics/glyph.c +38 -8
- data/ext/graphics/image.c +205 -41
- data/ext/graphics/polygon.c +317 -30
- data/ext/graphics/rect.c +225 -60
- data/ext/graphics/rectangle.c +307 -35
- data/ext/graphics/render_state.c +124 -12
- data/ext/graphics/render_texture.c +191 -14
- data/ext/graphics/render_window.c +55 -0
- data/ext/graphics/render_window.h +10 -0
- data/ext/graphics/shader.c +289 -17
- data/ext/graphics/shape.c +265 -32
- data/ext/graphics/sprite.c +245 -30
- data/ext/graphics/stencil_mode.c +163 -46
- data/ext/graphics/target.c +121 -43
- data/ext/graphics/target.h +31 -17
- data/ext/graphics/text.c +339 -19
- data/ext/graphics/texture.c +291 -6
- data/ext/graphics/transform.c +178 -5
- data/ext/graphics/transformable.c +127 -12
- data/ext/graphics/vertex.c +98 -6
- data/ext/graphics/vertex_array.c +142 -21
- data/ext/graphics/vertex_buffer.c +154 -12
- data/ext/graphics/view.c +140 -6
- data/ext/network/ftp.c +278 -12
- data/ext/network/http.c +179 -44
- data/ext/network/ip_address.c +127 -35
- data/ext/network/network_enums.c +248 -141
- data/ext/network/packet.c +280 -41
- data/ext/network/socket_selector.c +98 -21
- data/ext/network/tcp_listener.c +82 -18
- data/ext/network/tcp_socket.c +135 -27
- data/ext/network/udp_socket.c +129 -28
- data/ext/ports.rb +7 -0
- data/ext/system/buffer.c +47 -16
- data/ext/system/clock.c +77 -12
- data/ext/system/input_stream.c +113 -51
- data/ext/system/sleep.c +10 -2
- data/ext/system/time.c +182 -40
- data/ext/system/vec2.c +166 -39
- data/ext/system/vec3.c +177 -39
- data/ext/window/clipboard.c +47 -17
- data/ext/window/context.c +66 -13
- data/ext/window/context_settings.c +132 -42
- data/ext/window/cursor.c +45 -9
- data/ext/window/event.c +164 -53
- data/ext/window/joystick.c +69 -3
- data/ext/window/keyboard.c +168 -116
- data/ext/window/mouse.c +64 -13
- data/ext/window/sensor.c +28 -2
- data/ext/window/touch.c +32 -12
- data/ext/window/video_mode.c +93 -31
- data/ext/window/vulkan.c +34 -6
- data/ext/window/window.c +228 -229
- data/ext/window/window.h +4 -4
- data/ext/window/window_base.c +251 -0
- data/ext/window/window_base.h +43 -0
- data/ext/window/window_base.inc +236 -0
- data/lib/sfml/version.rb +1 -1
- data/sig/audio/audio_enums.rbs +30 -0
- data/sig/audio/listener.rbs +16 -0
- data/sig/audio/music.rbs +56 -0
- data/sig/audio/sound.rbs +51 -0
- data/sig/audio/sound_buffer.rbs +17 -0
- data/sig/audio/sound_buffer_recorder.rbs +14 -0
- data/sig/audio/sound_recorder.rbs +17 -0
- data/sig/audio/sound_source_cone.rbs +14 -0
- data/sig/audio/sound_stream.rbs +51 -0
- data/sig/graphics/blend_mode.rbs +29 -0
- data/sig/graphics/circle.rbs +44 -0
- data/sig/graphics/color.rbs +39 -0
- data/sig/graphics/drawable.rbs +5 -0
- data/sig/graphics/font.rbs +20 -0
- data/sig/graphics/glyph.rbs +7 -0
- data/sig/graphics/image.rbs +22 -0
- data/sig/graphics/polygon.rbs +42 -0
- data/sig/graphics/rect.rbs +33 -0
- data/sig/graphics/rectangle.rbs +42 -0
- data/sig/graphics/render_state.rbs +21 -0
- data/sig/graphics/render_target.rbs +18 -0
- data/sig/graphics/render_texture.rbs +39 -0
- data/sig/graphics/render_window.rbs +7 -0
- data/sig/graphics/shader.rbs +39 -0
- data/sig/graphics/shape.rbs +38 -0
- data/sig/graphics/sprite.rbs +34 -0
- data/sig/graphics/stencil_mode.rbs +18 -0
- data/sig/graphics/target.rbs +8 -0
- data/sig/graphics/text.rbs +48 -0
- data/sig/graphics/texture.rbs +34 -0
- data/sig/graphics/transform.rbs +37 -0
- data/sig/graphics/transformable.rbs +25 -0
- data/sig/graphics/vertex.rbs +17 -0
- data/sig/graphics/vertex_array.rbs +17 -0
- data/sig/graphics/vertex_buffer.rbs +22 -0
- data/sig/graphics/view.rbs +23 -0
- data/sig/network/ftp.rbs +46 -0
- data/sig/network/http.rbs +27 -0
- data/sig/network/ip_address.rbs +22 -0
- data/sig/network/network_enums.rbs +95 -0
- data/sig/network/packet.rbs +40 -0
- data/sig/network/socket_selector.rbs +14 -0
- data/sig/network/tcp_listener.rbs +13 -0
- data/sig/network/tcp_socket.rbs +18 -0
- data/sig/network/udp_socket.rbs +17 -0
- data/sig/sfml/version.rbs +3 -0
- data/sig/system/buffer.rbs +11 -0
- data/sig/system/clock.rbs +13 -0
- data/sig/system/input_stream.rbs +7 -0
- data/sig/system/sleep.rbs +3 -0
- data/sig/system/time.rbs +28 -0
- data/sig/system/vec2.rbs +26 -0
- data/sig/system/vec3.rbs +27 -0
- data/sig/window/clipboard.rbs +8 -0
- data/sig/window/context.rbs +11 -0
- data/sig/window/context_settings.rbs +20 -0
- data/sig/window/cursor.rbs +6 -0
- data/sig/window/event.rbs +20 -0
- data/sig/window/joystick.rbs +15 -0
- data/sig/window/keyboard.rbs +10 -0
- data/sig/window/mouse.rbs +9 -0
- data/sig/window/sensor.rbs +8 -0
- data/sig/window/touch.rbs +6 -0
- data/sig/window/video_mode.rbs +16 -0
- data/sig/window/vulkan.rbs +7 -0
- data/sig/window/window.rbs +34 -0
- data/sig/window/window_base.rbs +33 -0
- metadata +76 -3
data/ext/graphics/texture.c
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#include "graphics/texture.h"
|
|
2
2
|
|
|
3
3
|
#include <ruby.h>
|
|
4
|
+
#include <stdint.h>
|
|
4
5
|
#include <stdlib.h>
|
|
5
6
|
#include <string.h>
|
|
6
7
|
|
|
@@ -75,14 +76,69 @@ static const sfIntRect* Texture_area_ptr(VALUE rb_area, sfIntRect* storage) {
|
|
|
75
76
|
return storage;
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
static VALUE
|
|
79
|
-
|
|
79
|
+
static VALUE Texture_initialize_copy(VALUE self, VALUE other) {
|
|
80
|
+
(void)other;
|
|
81
|
+
rb_raise(rb_eTypeError, "can't copy a %s", rb_obj_classname(self));
|
|
80
82
|
}
|
|
81
83
|
|
|
84
|
+
static VALUE Texture_alloc(VALUE klass) {
|
|
85
|
+
Texture* ptr = malloc(sizeof(Texture));
|
|
86
|
+
|
|
87
|
+
if (ptr == NULL) {
|
|
88
|
+
rb_raise(rb_eNoMemError, "failed to allocate texture");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
ptr->texture = NULL;
|
|
92
|
+
ptr->owns = false;
|
|
93
|
+
|
|
94
|
+
return TypedData_Wrap_Struct(klass, &Texture_data_type, ptr);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* call-seq:
|
|
98
|
+
* Texture.new(size) -> Texture
|
|
99
|
+
*
|
|
100
|
+
* Creates an empty texture with the given +width+ and +height+.
|
|
101
|
+
*
|
|
102
|
+
* @return [Texture] an empty texture of +size+ (a Vector2 or 2-element Array)
|
|
103
|
+
* @raise [RuntimeError] if creation fails
|
|
104
|
+
*/
|
|
105
|
+
static VALUE Texture_initialize(VALUE self, VALUE rb_size) {
|
|
106
|
+
Texture* ptr;
|
|
107
|
+
sfTexture* texture = sfTexture_create(vec2u_from_rb(rb_size));
|
|
108
|
+
|
|
109
|
+
if (texture == NULL) {
|
|
110
|
+
rb_raise(rb_eRuntimeError, "failed to create texture");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
TypedData_Get_Struct(self, Texture, &Texture_data_type, ptr);
|
|
114
|
+
ptr->texture = texture;
|
|
115
|
+
ptr->owns = true;
|
|
116
|
+
|
|
117
|
+
return self;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* call-seq:
|
|
121
|
+
* Texture.srgb(size) -> Texture
|
|
122
|
+
*
|
|
123
|
+
* Creates an empty texture with an sRGB format.
|
|
124
|
+
*
|
|
125
|
+
* @return [Texture] an empty sRGB-encoded texture of +size+
|
|
126
|
+
* @raise [RuntimeError] if creation fails
|
|
127
|
+
*/
|
|
82
128
|
static VALUE Texture_srgb(VALUE klass, VALUE rb_size) {
|
|
83
129
|
return Texture_wrap(klass, sfTexture_createSrgb(vec2u_from_rb(rb_size)));
|
|
84
130
|
}
|
|
85
131
|
|
|
132
|
+
/* call-seq:
|
|
133
|
+
* Texture.from_file(path) -> Texture
|
|
134
|
+
* Texture.from_file(path, area) -> Texture
|
|
135
|
+
*
|
|
136
|
+
* Loads a texture from the image file at +filename+.
|
|
137
|
+
*
|
|
138
|
+
* @return [Texture] loaded from the file at +path+, cropped to +area+ (a
|
|
139
|
+
* Rect) if given
|
|
140
|
+
* @raise [RuntimeError] if loading fails
|
|
141
|
+
*/
|
|
86
142
|
static VALUE Texture_from_file(int argc, VALUE* argv, VALUE klass) {
|
|
87
143
|
VALUE rb_path, rb_area;
|
|
88
144
|
sfIntRect area;
|
|
@@ -93,6 +149,16 @@ static VALUE Texture_from_file(int argc, VALUE* argv, VALUE klass) {
|
|
|
93
149
|
Texture_area_ptr(rb_area, &area)));
|
|
94
150
|
}
|
|
95
151
|
|
|
152
|
+
/* call-seq:
|
|
153
|
+
* Texture.srgb_from_file(path) -> Texture
|
|
154
|
+
* Texture.srgb_from_file(path, area) -> Texture
|
|
155
|
+
*
|
|
156
|
+
* Loads an sRGB texture from the image file at +filename+.
|
|
157
|
+
*
|
|
158
|
+
* @return [Texture] sRGB-encoded, loaded from the file at +path+, cropped
|
|
159
|
+
* to +area+ (a Rect) if given
|
|
160
|
+
* @raise [RuntimeError] if loading fails
|
|
161
|
+
*/
|
|
96
162
|
static VALUE Texture_srgb_from_file(int argc, VALUE* argv, VALUE klass) {
|
|
97
163
|
VALUE rb_path, rb_area;
|
|
98
164
|
sfIntRect area;
|
|
@@ -103,6 +169,16 @@ static VALUE Texture_srgb_from_file(int argc, VALUE* argv, VALUE klass) {
|
|
|
103
169
|
Texture_area_ptr(rb_area, &area)));
|
|
104
170
|
}
|
|
105
171
|
|
|
172
|
+
/* call-seq:
|
|
173
|
+
* Texture.from_memory(data) -> Texture
|
|
174
|
+
* Texture.from_memory(data, area) -> Texture
|
|
175
|
+
*
|
|
176
|
+
* Loads a texture from an in-memory image buffer.
|
|
177
|
+
*
|
|
178
|
+
* @return [Texture] decoded from the encoded image bytes in +data+ (a
|
|
179
|
+
* String), cropped to +area+ (a Rect) if given
|
|
180
|
+
* @raise [RuntimeError] if decoding fails
|
|
181
|
+
*/
|
|
106
182
|
static VALUE Texture_from_memory(int argc, VALUE* argv, VALUE klass) {
|
|
107
183
|
VALUE rb_data, rb_area;
|
|
108
184
|
sfIntRect area;
|
|
@@ -115,6 +191,16 @@ static VALUE Texture_from_memory(int argc, VALUE* argv, VALUE klass) {
|
|
|
115
191
|
Texture_area_ptr(rb_area, &area)));
|
|
116
192
|
}
|
|
117
193
|
|
|
194
|
+
/* call-seq:
|
|
195
|
+
* Texture.srgb_from_memory(data) -> Texture
|
|
196
|
+
* Texture.srgb_from_memory(data, area) -> Texture
|
|
197
|
+
*
|
|
198
|
+
* Loads an sRGB texture from an in-memory image buffer.
|
|
199
|
+
*
|
|
200
|
+
* @return [Texture] sRGB-encoded, decoded from the encoded image bytes in
|
|
201
|
+
* +data+ (a String), cropped to +area+ (a Rect) if given
|
|
202
|
+
* @raise [RuntimeError] if decoding fails
|
|
203
|
+
*/
|
|
118
204
|
static VALUE Texture_srgb_from_memory(int argc, VALUE* argv, VALUE klass) {
|
|
119
205
|
VALUE rb_data, rb_area;
|
|
120
206
|
sfIntRect area;
|
|
@@ -127,6 +213,16 @@ static VALUE Texture_srgb_from_memory(int argc, VALUE* argv, VALUE klass) {
|
|
|
127
213
|
Texture_area_ptr(rb_area, &area)));
|
|
128
214
|
}
|
|
129
215
|
|
|
216
|
+
/* call-seq:
|
|
217
|
+
* Texture.from_stream(stream) -> Texture
|
|
218
|
+
* Texture.from_stream(stream, area) -> Texture
|
|
219
|
+
*
|
|
220
|
+
* Loads a texture from the image data read from +stream+.
|
|
221
|
+
*
|
|
222
|
+
* @return [Texture] decoded from +stream+ (an InputStream), cropped to
|
|
223
|
+
* +area+ (a Rect) if given
|
|
224
|
+
* @raise [RuntimeError] if decoding fails
|
|
225
|
+
*/
|
|
130
226
|
static VALUE Texture_from_stream(int argc, VALUE* argv, VALUE klass) {
|
|
131
227
|
VALUE rb_stream, rb_area, holder = Qnil;
|
|
132
228
|
sfIntRect area;
|
|
@@ -146,6 +242,16 @@ static VALUE Texture_from_stream(int argc, VALUE* argv, VALUE klass) {
|
|
|
146
242
|
sfTexture_createFromStream(stream, Texture_area_ptr(rb_area, &area)));
|
|
147
243
|
}
|
|
148
244
|
|
|
245
|
+
/* call-seq:
|
|
246
|
+
* Texture.srgb_from_stream(stream) -> Texture
|
|
247
|
+
* Texture.srgb_from_stream(stream, area) -> Texture
|
|
248
|
+
*
|
|
249
|
+
* Loads an sRGB texture from the image data read from +stream+.
|
|
250
|
+
*
|
|
251
|
+
* @return [Texture] sRGB-encoded, decoded from +stream+ (an InputStream),
|
|
252
|
+
* cropped to +area+ (a Rect) if given
|
|
253
|
+
* @raise [RuntimeError] if decoding fails
|
|
254
|
+
*/
|
|
149
255
|
static VALUE Texture_srgb_from_stream(int argc, VALUE* argv, VALUE klass) {
|
|
150
256
|
VALUE rb_stream, rb_area, holder = Qnil;
|
|
151
257
|
sfIntRect area;
|
|
@@ -165,6 +271,17 @@ static VALUE Texture_srgb_from_stream(int argc, VALUE* argv, VALUE klass) {
|
|
|
165
271
|
sfTexture_createSrgbFromStream(stream, Texture_area_ptr(rb_area, &area)));
|
|
166
272
|
}
|
|
167
273
|
|
|
274
|
+
/* call-seq:
|
|
275
|
+
* Texture.from_image(image) -> Texture
|
|
276
|
+
* Texture.from_image(image, area) -> Texture
|
|
277
|
+
*
|
|
278
|
+
* Creates a texture from the pixels of an existing Image.
|
|
279
|
+
*
|
|
280
|
+
* @return [Texture] built from +image+ (an Image), cropped to +area+ (a
|
|
281
|
+
* Rect) if given
|
|
282
|
+
* @raise [TypeError] if +image+ is not an Image
|
|
283
|
+
* @raise [RuntimeError] if creation fails
|
|
284
|
+
*/
|
|
168
285
|
static VALUE Texture_from_image(int argc, VALUE* argv, VALUE klass) {
|
|
169
286
|
VALUE rb_image, rb_area;
|
|
170
287
|
sfIntRect area;
|
|
@@ -179,6 +296,17 @@ static VALUE Texture_from_image(int argc, VALUE* argv, VALUE klass) {
|
|
|
179
296
|
Texture_area_ptr(rb_area, &area)));
|
|
180
297
|
}
|
|
181
298
|
|
|
299
|
+
/* call-seq:
|
|
300
|
+
* Texture.srgb_from_image(image) -> Texture
|
|
301
|
+
* Texture.srgb_from_image(image, area) -> Texture
|
|
302
|
+
*
|
|
303
|
+
* Creates an sRGB texture from the pixels of an existing Image.
|
|
304
|
+
*
|
|
305
|
+
* @return [Texture] sRGB-encoded, built from +image+ (an Image), cropped to
|
|
306
|
+
* +area+ (a Rect) if given
|
|
307
|
+
* @raise [TypeError] if +image+ is not an Image
|
|
308
|
+
* @raise [RuntimeError] if creation fails
|
|
309
|
+
*/
|
|
182
310
|
static VALUE Texture_srgb_from_image(int argc, VALUE* argv, VALUE klass) {
|
|
183
311
|
VALUE rb_image, rb_area;
|
|
184
312
|
sfIntRect area;
|
|
@@ -193,20 +321,47 @@ static VALUE Texture_srgb_from_image(int argc, VALUE* argv, VALUE klass) {
|
|
|
193
321
|
Texture_area_ptr(rb_area, &area)));
|
|
194
322
|
}
|
|
195
323
|
|
|
324
|
+
/* call-seq: copy -> Texture
|
|
325
|
+
*
|
|
326
|
+
* Returns a deep copy of the object.
|
|
327
|
+
*
|
|
328
|
+
* @return [Texture] an independent copy
|
|
329
|
+
*/
|
|
196
330
|
static VALUE Texture_copy(VALUE self) {
|
|
197
331
|
return Texture_wrap(Get_Klass_Texture(), sfTexture_copy(Get_Texture_Struct(self)));
|
|
198
332
|
}
|
|
199
333
|
|
|
334
|
+
/* call-seq: size -> Vector2
|
|
335
|
+
*
|
|
336
|
+
* Returns the object's size.
|
|
337
|
+
*
|
|
338
|
+
* @return [Vector2]
|
|
339
|
+
*/
|
|
200
340
|
static VALUE Texture_get_size(VALUE self) {
|
|
201
341
|
sfVector2u size = sfTexture_getSize(Get_Texture_Struct(self));
|
|
202
342
|
|
|
203
343
|
return vec2f_to_rb((sfVector2f){(float)size.x, (float)size.y});
|
|
204
344
|
}
|
|
205
345
|
|
|
346
|
+
/* call-seq:
|
|
347
|
+
* resize(size) -> true or false
|
|
348
|
+
*
|
|
349
|
+
* Resizes the texture in place. Existing pixel data is lost.
|
|
350
|
+
*
|
|
351
|
+
* @return [Boolean] whether resizing succeeded
|
|
352
|
+
*/
|
|
206
353
|
static VALUE Texture_resize(VALUE self, VALUE rb_size) {
|
|
207
354
|
return BOOL2RB(sfTexture_resize((sfTexture*)Get_Texture_Struct(self), vec2u_from_rb(rb_size)));
|
|
208
355
|
}
|
|
209
356
|
|
|
357
|
+
/* call-seq:
|
|
358
|
+
* resize_srgb(size) -> true or false
|
|
359
|
+
*
|
|
360
|
+
* Resizes the texture in place as sRGB-encoded. Existing pixel data is
|
|
361
|
+
* lost.
|
|
362
|
+
*
|
|
363
|
+
* @return [Boolean] whether resizing succeeded
|
|
364
|
+
*/
|
|
210
365
|
static VALUE Texture_resize_srgb(VALUE self, VALUE rb_size) {
|
|
211
366
|
return BOOL2RB(
|
|
212
367
|
sfTexture_resizeSrgb((sfTexture*)Get_Texture_Struct(self), vec2u_from_rb(rb_size)));
|
|
@@ -214,6 +369,14 @@ static VALUE Texture_resize_srgb(VALUE self, VALUE rb_size) {
|
|
|
214
369
|
|
|
215
370
|
/* Exchanges the two textures' contents in place, so anything already holding
|
|
216
371
|
either object sees the swap. */
|
|
372
|
+
/* call-seq:
|
|
373
|
+
* swap(other) -> self
|
|
374
|
+
*
|
|
375
|
+
* Swaps the contents with +other+.
|
|
376
|
+
*
|
|
377
|
+
* @return [self]
|
|
378
|
+
* @raise [TypeError] if +other+ is not a Texture
|
|
379
|
+
*/
|
|
217
380
|
static VALUE Texture_swap(VALUE self, VALUE rb_other) {
|
|
218
381
|
if (!rb_obj_is_kind_of(rb_other, Get_Klass_Texture())) {
|
|
219
382
|
raise_invalid_argument_class(Get_Klass_Texture());
|
|
@@ -224,6 +387,13 @@ static VALUE Texture_swap(VALUE self, VALUE rb_other) {
|
|
|
224
387
|
return self;
|
|
225
388
|
}
|
|
226
389
|
|
|
390
|
+
/* call-seq: copy_to_image -> Image
|
|
391
|
+
*
|
|
392
|
+
* Copies the texture's pixels into +image+.
|
|
393
|
+
*
|
|
394
|
+
* @return [Image] the texture's pixels, read back from the GPU
|
|
395
|
+
* @raise [RuntimeError] if the copy fails
|
|
396
|
+
*/
|
|
227
397
|
static VALUE Texture_copy_to_image(VALUE self) {
|
|
228
398
|
sfImage* image = sfTexture_copyToImage(Get_Texture_Struct(self));
|
|
229
399
|
|
|
@@ -234,14 +404,34 @@ static VALUE Texture_copy_to_image(VALUE self) {
|
|
|
234
404
|
return image_from_c(image);
|
|
235
405
|
}
|
|
236
406
|
|
|
407
|
+
/* call-seq:
|
|
408
|
+
* update_from_pixels(pixels, size, offset) -> self
|
|
409
|
+
*
|
|
410
|
+
* Overwrites a +size+ region of the texture at +offset+ with +pixels+ (a
|
|
411
|
+
* String of raw RGBA8 bytes, +size.x * size.y * 4+ long).
|
|
412
|
+
*
|
|
413
|
+
* @return [self]
|
|
414
|
+
* @raise [ArgumentError] if +pixels+ is shorter than required
|
|
415
|
+
*/
|
|
237
416
|
static VALUE Texture_update_from_pixels(VALUE self, VALUE rb_pixels, VALUE rb_size,
|
|
238
417
|
VALUE rb_offset) {
|
|
239
418
|
sfVector2u size = vec2u_from_rb(rb_size);
|
|
240
419
|
sfVector2u offset = vec2u_from_rb(rb_offset);
|
|
420
|
+
size_t expected;
|
|
421
|
+
|
|
422
|
+
/* size.x * size.y * 4 as a bare size_t multiplication can wrap on the
|
|
423
|
+
32-bit targets this gem ships; check before multiplying rather than
|
|
424
|
+
after so a wrapped-to-near-zero "expected" can't slip a too-short
|
|
425
|
+
buffer past the length check below (see the identical fix in
|
|
426
|
+
graphics/image.c). */
|
|
427
|
+
if (size.x != 0 && size.y > (SIZE_MAX / 4) / size.x) {
|
|
428
|
+
rb_raise(rb_eArgError, "texture dimensions too large");
|
|
429
|
+
}
|
|
430
|
+
expected = (size_t)size.x * size.y * 4;
|
|
241
431
|
|
|
242
432
|
StringValue(rb_pixels);
|
|
243
433
|
|
|
244
|
-
if ((size_t)RSTRING_LEN(rb_pixels) <
|
|
434
|
+
if ((size_t)RSTRING_LEN(rb_pixels) < expected) {
|
|
245
435
|
rb_raise(rb_eArgError, "pixel data too short");
|
|
246
436
|
}
|
|
247
437
|
|
|
@@ -251,6 +441,14 @@ static VALUE Texture_update_from_pixels(VALUE self, VALUE rb_pixels, VALUE rb_si
|
|
|
251
441
|
return self;
|
|
252
442
|
}
|
|
253
443
|
|
|
444
|
+
/* call-seq:
|
|
445
|
+
* update_from_image(image, offset) -> self
|
|
446
|
+
*
|
|
447
|
+
* Updates the texture from the pixels of +image+.
|
|
448
|
+
*
|
|
449
|
+
* @return [self]
|
|
450
|
+
* @raise [TypeError] if +image+ is not an Image
|
|
451
|
+
*/
|
|
254
452
|
static VALUE Texture_update_from_image(VALUE self, VALUE rb_image, VALUE rb_offset) {
|
|
255
453
|
if (!rb_obj_is_kind_of(rb_image, Get_Klass_Image())) {
|
|
256
454
|
raise_invalid_argument_class(Get_Klass_Image());
|
|
@@ -262,6 +460,14 @@ static VALUE Texture_update_from_image(VALUE self, VALUE rb_image, VALUE rb_offs
|
|
|
262
460
|
return self;
|
|
263
461
|
}
|
|
264
462
|
|
|
463
|
+
/* call-seq:
|
|
464
|
+
* update_from_texture(source, offset) -> self
|
|
465
|
+
*
|
|
466
|
+
* Updates the texture from the pixels of another texture.
|
|
467
|
+
*
|
|
468
|
+
* @return [self]
|
|
469
|
+
* @raise [TypeError] if +source+ is not a Texture
|
|
470
|
+
*/
|
|
265
471
|
static VALUE Texture_update_from_texture(VALUE self, VALUE rb_source, VALUE rb_offset) {
|
|
266
472
|
if (!rb_obj_is_kind_of(rb_source, rb_cTexture)) {
|
|
267
473
|
raise_invalid_argument_class(rb_cTexture);
|
|
@@ -273,6 +479,14 @@ static VALUE Texture_update_from_texture(VALUE self, VALUE rb_source, VALUE rb_o
|
|
|
273
479
|
return self;
|
|
274
480
|
}
|
|
275
481
|
|
|
482
|
+
/* call-seq:
|
|
483
|
+
* update_from_window(window, offset) -> self
|
|
484
|
+
*
|
|
485
|
+
* Updates the texture from the contents of a window.
|
|
486
|
+
*
|
|
487
|
+
* @return [self]
|
|
488
|
+
* @raise [TypeError] if +window+ is not a Window
|
|
489
|
+
*/
|
|
276
490
|
static VALUE Texture_update_from_window(VALUE self, VALUE rb_window, VALUE rb_offset) {
|
|
277
491
|
if (!rb_obj_is_kind_of(rb_window, Get_Klass_Window())) {
|
|
278
492
|
raise_invalid_argument_class(Get_Klass_Window());
|
|
@@ -284,36 +498,90 @@ static VALUE Texture_update_from_window(VALUE self, VALUE rb_window, VALUE rb_of
|
|
|
284
498
|
return self;
|
|
285
499
|
}
|
|
286
500
|
|
|
501
|
+
/* call-seq:
|
|
502
|
+
* smooth=(value) -> true or false
|
|
503
|
+
*
|
|
504
|
+
* Enables or disables smooth rendering.
|
|
505
|
+
*
|
|
506
|
+
* @return [Boolean] +value+
|
|
507
|
+
*/
|
|
287
508
|
static VALUE Texture_set_smooth(VALUE self, VALUE rb_smooth) {
|
|
288
509
|
sfTexture_setSmooth((sfTexture*)Get_Texture_Struct(self), RTEST(rb_smooth));
|
|
289
510
|
return rb_smooth;
|
|
290
511
|
}
|
|
291
512
|
|
|
513
|
+
/* call-seq: smooth? -> true or false
|
|
514
|
+
*
|
|
515
|
+
* Returns +true+ if smooth rendering is enabled.
|
|
516
|
+
*
|
|
517
|
+
* @return [Boolean]
|
|
518
|
+
*/
|
|
292
519
|
static VALUE Texture_is_smooth(VALUE self) {
|
|
293
520
|
return BOOL2RB(sfTexture_isSmooth(Get_Texture_Struct(self)));
|
|
294
521
|
}
|
|
295
522
|
|
|
523
|
+
/* call-seq: srgb? -> true or false
|
|
524
|
+
*
|
|
525
|
+
* Returns +true+ if the texture uses an sRGB format.
|
|
526
|
+
*
|
|
527
|
+
* @return [Boolean]
|
|
528
|
+
*/
|
|
296
529
|
static VALUE Texture_is_srgb(VALUE self) {
|
|
297
530
|
return BOOL2RB(sfTexture_isSrgb(Get_Texture_Struct(self)));
|
|
298
531
|
}
|
|
299
532
|
|
|
533
|
+
/* call-seq:
|
|
534
|
+
* repeated=(value) -> true or false
|
|
535
|
+
*
|
|
536
|
+
* Enables or disables texture repeating.
|
|
537
|
+
*
|
|
538
|
+
* @return [Boolean] +value+
|
|
539
|
+
*/
|
|
300
540
|
static VALUE Texture_set_repeated(VALUE self, VALUE rb_repeated) {
|
|
301
541
|
sfTexture_setRepeated((sfTexture*)Get_Texture_Struct(self), RTEST(rb_repeated));
|
|
302
542
|
return rb_repeated;
|
|
303
543
|
}
|
|
304
544
|
|
|
545
|
+
/* call-seq: repeated? -> true or false
|
|
546
|
+
*
|
|
547
|
+
* Returns +true+ if texture repeating is enabled.
|
|
548
|
+
*
|
|
549
|
+
* @return [Boolean]
|
|
550
|
+
*/
|
|
305
551
|
static VALUE Texture_is_repeated(VALUE self) {
|
|
306
552
|
return BOOL2RB(sfTexture_isRepeated(Get_Texture_Struct(self)));
|
|
307
553
|
}
|
|
308
554
|
|
|
555
|
+
/* call-seq: generate_mipmap -> true or false
|
|
556
|
+
*
|
|
557
|
+
* Generates the mipmap pyramid for the texture.
|
|
558
|
+
*
|
|
559
|
+
* @return [Boolean] whether mipmap generation succeeded
|
|
560
|
+
*/
|
|
309
561
|
static VALUE Texture_generate_mipmap(VALUE self) {
|
|
310
562
|
return BOOL2RB(sfTexture_generateMipmap((sfTexture*)Get_Texture_Struct(self)));
|
|
311
563
|
}
|
|
312
564
|
|
|
565
|
+
/* call-seq: native_handle -> Integer
|
|
566
|
+
*
|
|
567
|
+
* Returns the underlying OpenGL handle.
|
|
568
|
+
*
|
|
569
|
+
* @return [Integer] the underlying OpenGL texture handle
|
|
570
|
+
*/
|
|
313
571
|
static VALUE Texture_get_native_handle(VALUE self) {
|
|
314
572
|
return UINT2NUM(sfTexture_getNativeHandle(Get_Texture_Struct(self)));
|
|
315
573
|
}
|
|
316
574
|
|
|
575
|
+
/* call-seq:
|
|
576
|
+
* bind -> self
|
|
577
|
+
* bind(coordinate_type) -> self
|
|
578
|
+
*
|
|
579
|
+
* Activates this texture for rendering. +coordinate_type+ selects
|
|
580
|
+
* normalized (0..1) or pixel texture coordinates and defaults to
|
|
581
|
+
* normalized.
|
|
582
|
+
*
|
|
583
|
+
* @return [self]
|
|
584
|
+
*/
|
|
317
585
|
static VALUE Texture_bind(int argc, VALUE* argv, VALUE self) {
|
|
318
586
|
VALUE rb_coordinate_type;
|
|
319
587
|
sfCoordinateType type = sfCoordinateTypeNormalized;
|
|
@@ -329,14 +597,31 @@ static VALUE Texture_bind(int argc, VALUE* argv, VALUE self) {
|
|
|
329
597
|
return self;
|
|
330
598
|
}
|
|
331
599
|
|
|
600
|
+
/* call-seq:
|
|
601
|
+
* Texture.maximum_size -> Integer
|
|
602
|
+
*
|
|
603
|
+
* Returns the maximum texture size supported by the GPU.
|
|
604
|
+
*
|
|
605
|
+
* @return [Integer] the maximum texture size supported by the current
|
|
606
|
+
* OpenGL implementation
|
|
607
|
+
*/
|
|
332
608
|
static VALUE Texture_maximum_size(VALUE klass) {
|
|
333
609
|
return UINT2NUM(sfTexture_getMaximumSize());
|
|
334
610
|
}
|
|
335
611
|
|
|
336
|
-
|
|
337
|
-
|
|
612
|
+
/* Document-class: SFML::Texture
|
|
613
|
+
* An image living in GPU memory, usable for rendering (Sprite, Text,
|
|
614
|
+
* Shape) or as a render target (RenderTexture#texture).
|
|
615
|
+
*
|
|
616
|
+
* #smooth?/#smooth=, #srgb?, and #repeated?/#repeated= control sampling;
|
|
617
|
+
* see each method for details.
|
|
618
|
+
*/
|
|
619
|
+
void Init_Texture(VALUE rb_mSFML) {
|
|
620
|
+
rb_cTexture = rb_define_class_under(rb_mSFML, "Texture", rb_cObject);
|
|
338
621
|
|
|
339
|
-
|
|
622
|
+
rb_define_alloc_func(rb_cTexture, Texture_alloc);
|
|
623
|
+
rb_define_method(rb_cTexture, "initialize", Texture_initialize, 1);
|
|
624
|
+
rb_define_private_method(rb_cTexture, "initialize_copy", Texture_initialize_copy, 1);
|
|
340
625
|
rb_define_singleton_method(rb_cTexture, "from_file", Texture_from_file, -1);
|
|
341
626
|
rb_define_singleton_method(rb_cTexture, "from_memory", Texture_from_memory, -1);
|
|
342
627
|
rb_define_singleton_method(rb_cTexture, "from_stream", Texture_from_stream, -1);
|