gosu 1.4.6 → 1.5.0
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/COPYING +2 -1
- data/dependencies/SDL/include/SDL3/SDL.h +91 -0
- data/dependencies/SDL/include/SDL3/SDL_assert.h +710 -0
- data/dependencies/SDL/include/SDL3/SDL_asyncio.h +550 -0
- data/dependencies/SDL/include/SDL3/SDL_atomic.h +692 -0
- data/dependencies/SDL/include/SDL3/SDL_audio.h +2382 -0
- data/dependencies/SDL/include/SDL3/SDL_begin_code.h +553 -0
- data/dependencies/SDL/include/{SDL_bits.h → SDL3/SDL_bits.h} +47 -27
- data/dependencies/SDL/include/{SDL_blendmode.h → SDL3/SDL_blendmode.h} +59 -55
- data/dependencies/SDL/include/SDL3/SDL_camera.h +535 -0
- data/dependencies/SDL/include/SDL3/SDL_clipboard.h +331 -0
- data/dependencies/SDL/include/{close_code.h → SDL3/SDL_close_code.h} +9 -8
- data/dependencies/SDL/include/{SDL_types.h → SDL3/SDL_copying.h} +2 -9
- data/dependencies/SDL/include/SDL3/SDL_cpuinfo.h +374 -0
- data/dependencies/SDL/include/SDL3/SDL_dialog.h +343 -0
- data/dependencies/SDL/include/SDL3/SDL_dlopennote.h +234 -0
- data/dependencies/SDL/include/{SDL_egl.h → SDL3/SDL_egl.h} +11 -8
- data/dependencies/SDL/include/SDL3/SDL_endian.h +645 -0
- data/dependencies/SDL/include/SDL3/SDL_error.h +226 -0
- data/dependencies/SDL/include/SDL3/SDL_events.h +1651 -0
- data/dependencies/SDL/include/SDL3/SDL_filesystem.h +537 -0
- data/dependencies/SDL/include/SDL3/SDL_gamepad.h +1657 -0
- data/dependencies/SDL/include/SDL3/SDL_gpu.h +4637 -0
- data/dependencies/SDL/include/SDL3/SDL_guid.h +106 -0
- data/dependencies/SDL/include/SDL3/SDL_haptic.h +1461 -0
- data/dependencies/SDL/include/SDL3/SDL_hidapi.h +571 -0
- data/dependencies/SDL/include/SDL3/SDL_hints.h +5041 -0
- data/dependencies/SDL/include/SDL3/SDL_init.h +508 -0
- data/dependencies/SDL/include/SDL3/SDL_intrin.h +410 -0
- data/dependencies/SDL/include/SDL3/SDL_iostream.h +1379 -0
- data/dependencies/SDL/include/SDL3/SDL_joystick.h +1385 -0
- data/dependencies/SDL/include/SDL3/SDL_keyboard.h +615 -0
- data/dependencies/SDL/include/SDL3/SDL_keycode.h +348 -0
- data/dependencies/SDL/include/SDL3/SDL_loadso.h +145 -0
- data/dependencies/SDL/include/{SDL_locale.h → SDL3/SDL_locale.h} +40 -24
- data/dependencies/SDL/include/SDL3/SDL_log.h +541 -0
- data/dependencies/SDL/include/SDL3/SDL_main.h +704 -0
- data/dependencies/SDL/include/SDL3/SDL_main_impl.h +149 -0
- data/dependencies/SDL/include/{SDL_messagebox.h → SDL3/SDL_messagebox.h} +85 -48
- data/dependencies/SDL/include/{SDL_metal.h → SDL3/SDL_metal.h} +29 -29
- data/dependencies/SDL/include/{SDL_misc.h → SDL3/SDL_misc.h} +13 -12
- data/dependencies/SDL/include/SDL3/SDL_mouse.h +813 -0
- data/dependencies/SDL/include/SDL3/SDL_mutex.h +1117 -0
- data/dependencies/SDL/include/SDL3/SDL_oldnames.h +1339 -0
- data/dependencies/SDL/include/{SDL_opengl.h → SDL3/SDL_opengl.h} +1247 -278
- data/dependencies/SDL/include/{SDL_opengl_glext.h → SDL3/SDL_opengl_glext.h} +5 -1
- data/dependencies/SDL/include/{SDL_opengles.h → SDL3/SDL_opengles.h} +6 -7
- data/dependencies/SDL/include/{SDL_opengles2.h → SDL3/SDL_opengles2.h} +10 -11
- data/dependencies/SDL/include/SDL3/SDL_pen.h +198 -0
- data/dependencies/SDL/include/SDL3/SDL_pixels.h +1441 -0
- data/dependencies/SDL/include/{SDL_test_log.h → SDL3/SDL_platform.h} +25 -26
- data/dependencies/SDL/include/SDL3/SDL_platform_defines.h +497 -0
- data/dependencies/SDL/include/{SDL_power.h → SDL3/SDL_power.h} +40 -20
- data/dependencies/SDL/include/SDL3/SDL_process.h +441 -0
- data/dependencies/SDL/include/SDL3/SDL_properties.h +572 -0
- data/dependencies/SDL/include/SDL3/SDL_rect.h +528 -0
- data/dependencies/SDL/include/SDL3/SDL_render.h +3034 -0
- data/dependencies/SDL/include/SDL3/SDL_revision.h +56 -0
- data/dependencies/SDL/include/{SDL_scancode.h → SDL3/SDL_scancode.h} +60 -68
- data/dependencies/SDL/include/SDL3/SDL_sensor.h +321 -0
- data/dependencies/SDL/include/SDL3/SDL_stdinc.h +6186 -0
- data/dependencies/SDL/include/SDL3/SDL_storage.h +686 -0
- data/dependencies/SDL/include/SDL3/SDL_surface.h +1769 -0
- data/dependencies/SDL/include/SDL3/SDL_system.h +840 -0
- data/dependencies/SDL/include/{SDL_test.h → SDL3/SDL_test.h} +16 -22
- data/dependencies/SDL/include/{SDL_test_assert.h → SDL3/SDL_test_assert.h} +27 -34
- data/dependencies/SDL/include/{SDL_test_common.h → SDL3/SDL_test_common.h} +109 -52
- data/dependencies/SDL/include/{SDL_test_compare.h → SDL3/SDL_test_compare.h} +22 -14
- data/dependencies/SDL/include/{SDL_test_crc32.h → SDL3/SDL_test_crc32.h} +27 -30
- data/dependencies/SDL/include/{SDL_test_font.h → SDL3/SDL_test_font.h} +50 -49
- data/dependencies/SDL/include/{SDL_test_fuzzer.h → SDL3/SDL_test_fuzzer.h} +64 -79
- data/dependencies/SDL/include/{SDL_test_harness.h → SDL3/SDL_test_harness.h} +47 -30
- data/dependencies/SDL/include/SDL3/SDL_test_log.h +83 -0
- data/dependencies/SDL/include/{SDL_test_md5.h → SDL3/SDL_test_md5.h} +21 -28
- data/dependencies/SDL/include/{SDL_test_memory.h → SDL3/SDL_test_memory.h} +19 -16
- data/dependencies/SDL/include/SDL3/SDL_thread.h +602 -0
- data/dependencies/SDL/include/SDL3/SDL_time.h +249 -0
- data/dependencies/SDL/include/SDL3/SDL_timer.h +454 -0
- data/dependencies/SDL/include/SDL3/SDL_touch.h +184 -0
- data/dependencies/SDL/include/SDL3/SDL_tray.h +544 -0
- data/dependencies/SDL/include/SDL3/SDL_version.h +198 -0
- data/dependencies/SDL/include/SDL3/SDL_video.h +3497 -0
- data/dependencies/SDL/include/SDL3/SDL_vulkan.h +287 -0
- data/dependencies/SDL/lib/x64/libSDL3.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL3.dll.a +0 -0
- data/dependencies/SDL_sound/SDL3_sound/SDL_sound.h +755 -0
- data/dependencies/SDL_sound/SDL_sound.c +136 -215
- data/dependencies/SDL_sound/SDL_sound_aiff.c +55 -54
- data/dependencies/SDL_sound/SDL_sound_au.c +32 -32
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +24 -41
- data/dependencies/SDL_sound/SDL_sound_flac.c +32 -12
- data/dependencies/SDL_sound/SDL_sound_internal.h +33 -48
- data/dependencies/SDL_sound/SDL_sound_modplug.c +21 -29
- data/dependencies/SDL_sound/SDL_sound_mp3.c +35 -13
- data/dependencies/SDL_sound/SDL_sound_raw.c +14 -15
- data/dependencies/SDL_sound/SDL_sound_shn.c +82 -82
- data/dependencies/SDL_sound/SDL_sound_voc.c +30 -30
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +34 -25
- data/dependencies/SDL_sound/SDL_sound_wav.c +86 -82
- data/dependencies/SDL_sound/dr_flac.h +1890 -1301
- data/dependencies/SDL_sound/dr_mp3.h +1098 -660
- data/dependencies/SDL_sound/libmodplug/fastmix.c +1 -1
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +5 -4
- data/dependencies/SDL_sound/libmodplug/load_ams.c +6 -3
- data/dependencies/SDL_sound/libmodplug/load_dsm.c +2 -1
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +2 -2
- data/dependencies/SDL_sound/libmodplug/modplug.h +2 -1
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +3 -3
- data/dependencies/SDL_sound/libmodplug/sndfile.c +3 -0
- data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -3
- data/dependencies/SDL_sound/stb_vorbis.h +397 -342
- data/dependencies/mojoAL/AL/alc.h +2 -2
- data/dependencies/mojoAL/mojoal.c +2120 -1885
- data/dependencies/stb/stb_image.h +1190 -1379
- data/dependencies/stb/stb_image_write.h +329 -129
- data/dependencies/stb/stb_truetype.h +304 -60
- data/dependencies/utf8proc/utf8proc.c +133 -75
- data/dependencies/utf8proc/utf8proc.h +131 -50
- data/dependencies/utf8proc/utf8proc_data.h +16213 -15658
- data/ext/gosu-ffi/extconf.rb +103 -0
- data/ext/gosu-ffi/gosu-ffi.def +467 -0
- data/ffi/Gosu.cpp +330 -0
- data/ffi/Gosu.h +84 -0
- data/ffi/Gosu_Channel.cpp +62 -0
- data/ffi/Gosu_Channel.h +17 -0
- data/ffi/Gosu_Color.cpp +176 -0
- data/ffi/Gosu_Color.h +31 -0
- data/ffi/Gosu_Constants.cpp +334 -0
- data/ffi/Gosu_FFI.h +34 -0
- data/ffi/Gosu_FFI_internal.h +160 -0
- data/ffi/Gosu_Font.cpp +97 -0
- data/ffi/Gosu_Font.h +32 -0
- data/ffi/Gosu_Image.cpp +239 -0
- data/ffi/Gosu_Image.h +71 -0
- data/ffi/Gosu_Sample.cpp +29 -0
- data/ffi/Gosu_Sample.h +14 -0
- data/ffi/Gosu_Song.cpp +69 -0
- data/ffi/Gosu_Song.h +18 -0
- data/ffi/Gosu_TextInput.cpp +94 -0
- data/ffi/Gosu_TextInput.h +25 -0
- data/ffi/Gosu_Window.cpp +314 -0
- data/ffi/Gosu_Window.h +78 -0
- data/include/Gosu/Audio.hpp +6 -11
- data/include/Gosu/Bitmap.hpp +38 -53
- data/include/Gosu/Buffer.hpp +54 -0
- data/include/Gosu/Color.hpp +29 -36
- data/include/Gosu/Directories.hpp +25 -28
- data/include/Gosu/Drawable.hpp +58 -0
- data/include/Gosu/Font.hpp +6 -5
- data/include/Gosu/Fwd.hpp +4 -6
- data/include/Gosu/Gosu.hpp +5 -5
- data/include/Gosu/Graphics.hpp +53 -61
- data/include/Gosu/GraphicsBase.hpp +1 -11
- data/include/Gosu/Image.hpp +12 -15
- data/include/Gosu/Math.hpp +50 -72
- data/include/Gosu/Transform.hpp +32 -0
- data/include/Gosu/Utility.hpp +77 -1
- data/include/Gosu/Version.hpp +2 -2
- data/include/Gosu/Window.hpp +15 -9
- data/lib/SDL3.dll +0 -0
- data/lib/gosu/channel.rb +50 -0
- data/lib/gosu/color.rb +173 -0
- data/lib/gosu/compat.rb +130 -17
- data/lib/gosu/constants.rb +386 -0
- data/lib/gosu/ffi.rb +269 -0
- data/lib/gosu/font.rb +62 -0
- data/lib/gosu/gl_tex_info.rb +33 -0
- data/lib/gosu/gosu.rb +250 -0
- data/lib/gosu/image.rb +179 -0
- data/lib/gosu/numeric.rb +17 -0
- data/lib/gosu/preview.rb +6 -6
- data/lib/gosu/sample.rb +25 -0
- data/lib/gosu/song.rb +57 -0
- data/lib/gosu/text_input.rb +83 -0
- data/lib/gosu/window.rb +249 -0
- data/lib/gosu.rb +29 -8
- data/lib64/SDL3.dll +0 -0
- data/rdoc/gosu.rb +2 -2
- data/src/Audio.cpp +30 -24
- data/src/AudioFile.hpp +5 -4
- data/src/AudioFileAudioToolbox.cpp +8 -8
- data/src/AudioFileSDLSound.cpp +12 -15
- data/src/BinPacker.cpp +188 -0
- data/src/BinPacker.hpp +55 -0
- data/src/Bitmap.cpp +172 -143
- data/src/BitmapIO.cpp +60 -86
- data/src/Buffer.cpp +150 -0
- data/src/ClipRectStack.cpp +38 -0
- data/src/ClipRectStack.hpp +17 -83
- data/src/Color.cpp +75 -80
- data/src/Directories.cpp +47 -0
- data/src/DirectoriesUIKit.cpp +50 -0
- data/src/DrawOp.hpp +20 -18
- data/src/DrawOpQueue.hpp +27 -33
- data/src/Drawable.cpp +95 -0
- data/src/EmptyDrawable.hpp +38 -0
- data/src/FPS.cpp +31 -0
- data/src/Font.cpp +104 -74
- data/src/GosuGLView.cpp +13 -11
- data/src/GosuViewController.cpp +2 -10
- data/src/Graphics.cpp +86 -145
- data/src/GraphicsImpl.hpp +14 -68
- data/src/Image.cpp +41 -35
- data/src/Input.cpp +73 -78
- data/src/Macro.cpp +46 -29
- data/src/Macro.hpp +23 -17
- data/src/MarkupParser.cpp +5 -5
- data/src/Math.cpp +48 -22
- data/src/OffScreenTarget.cpp +47 -50
- data/src/OffScreenTarget.hpp +13 -11
- data/src/OpenGLContext.cpp +116 -0
- data/src/OpenGLContext.hpp +41 -0
- data/src/RenderState.hpp +49 -71
- data/src/Resolution.cpp +65 -53
- data/src/TexChunk.cpp +35 -80
- data/src/TexChunk.hpp +44 -35
- data/src/Text.cpp +1 -1
- data/src/TextBuilder.cpp +35 -21
- data/src/TextBuilder.hpp +6 -9
- data/src/TextInput.cpp +9 -9
- data/src/Texture.cpp +62 -80
- data/src/Texture.hpp +25 -23
- data/src/TiledDrawable.cpp +149 -0
- data/src/TiledDrawable.hpp +47 -0
- data/src/TimingApple.cpp +1 -1
- data/src/Transform.cpp +45 -50
- data/src/TransformStack.hpp +16 -16
- data/src/TrueTypeFont.cpp +59 -51
- data/src/TrueTypeFont.hpp +6 -7
- data/src/TrueTypeFontApple.cpp +28 -19
- data/src/TrueTypeFontUnix.cpp +39 -32
- data/src/TrueTypeFontWin.cpp +30 -30
- data/src/Utility.cpp +113 -37
- data/src/UtilityWin.cpp +49 -0
- data/src/Window.cpp +121 -151
- data/src/WindowUIKit.cpp +14 -14
- metadata +165 -118
- data/dependencies/SDL/include/SDL.h +0 -233
- data/dependencies/SDL/include/SDL_assert.h +0 -320
- data/dependencies/SDL/include/SDL_atomic.h +0 -415
- data/dependencies/SDL/include/SDL_audio.h +0 -1500
- data/dependencies/SDL/include/SDL_clipboard.h +0 -141
- data/dependencies/SDL/include/SDL_config.h +0 -331
- data/dependencies/SDL/include/SDL_cpuinfo.h +0 -594
- data/dependencies/SDL/include/SDL_endian.h +0 -348
- data/dependencies/SDL/include/SDL_error.h +0 -163
- data/dependencies/SDL/include/SDL_events.h +0 -1166
- data/dependencies/SDL/include/SDL_filesystem.h +0 -149
- data/dependencies/SDL/include/SDL_gamecontroller.h +0 -1074
- data/dependencies/SDL/include/SDL_gesture.h +0 -117
- data/dependencies/SDL/include/SDL_guid.h +0 -100
- data/dependencies/SDL/include/SDL_haptic.h +0 -1341
- data/dependencies/SDL/include/SDL_hidapi.h +0 -451
- data/dependencies/SDL/include/SDL_hints.h +0 -2569
- data/dependencies/SDL/include/SDL_joystick.h +0 -1066
- data/dependencies/SDL/include/SDL_keyboard.h +0 -353
- data/dependencies/SDL/include/SDL_keycode.h +0 -358
- data/dependencies/SDL/include/SDL_loadso.h +0 -115
- data/dependencies/SDL/include/SDL_log.h +0 -404
- data/dependencies/SDL/include/SDL_main.h +0 -275
- data/dependencies/SDL/include/SDL_mouse.h +0 -465
- data/dependencies/SDL/include/SDL_mutex.h +0 -471
- data/dependencies/SDL/include/SDL_name.h +0 -33
- data/dependencies/SDL/include/SDL_pixels.h +0 -644
- data/dependencies/SDL/include/SDL_platform.h +0 -261
- data/dependencies/SDL/include/SDL_quit.h +0 -58
- data/dependencies/SDL/include/SDL_rect.h +0 -376
- data/dependencies/SDL/include/SDL_render.h +0 -1919
- data/dependencies/SDL/include/SDL_revision.h +0 -7
- data/dependencies/SDL/include/SDL_rwops.h +0 -841
- data/dependencies/SDL/include/SDL_sensor.h +0 -322
- data/dependencies/SDL/include/SDL_shape.h +0 -155
- data/dependencies/SDL/include/SDL_stdinc.h +0 -830
- data/dependencies/SDL/include/SDL_surface.h +0 -997
- data/dependencies/SDL/include/SDL_system.h +0 -623
- data/dependencies/SDL/include/SDL_syswm.h +0 -386
- data/dependencies/SDL/include/SDL_test_images.h +0 -78
- data/dependencies/SDL/include/SDL_test_random.h +0 -115
- data/dependencies/SDL/include/SDL_thread.h +0 -464
- data/dependencies/SDL/include/SDL_timer.h +0 -222
- data/dependencies/SDL/include/SDL_touch.h +0 -150
- data/dependencies/SDL/include/SDL_version.h +0 -204
- data/dependencies/SDL/include/SDL_video.h +0 -2150
- data/dependencies/SDL/include/SDL_vulkan.h +0 -215
- data/dependencies/SDL/include/begin_code.h +0 -187
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.h +0 -725
- data/ext/gosu/extconf.rb +0 -119
- data/include/Gosu/IO.hpp +0 -254
- data/include/Gosu/ImageData.hpp +0 -53
- data/include/Gosu/Inspection.hpp +0 -7
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/patches.rb +0 -66
- data/lib/gosu/run.rb +0 -20
- data/lib/gosu/swig_patches.rb +0 -110
- data/lib64/SDL2.dll +0 -0
- data/src/BlockAllocator.cpp +0 -131
- data/src/BlockAllocator.hpp +0 -32
- data/src/DirectoriesApple.cpp +0 -69
- data/src/DirectoriesUnix.cpp +0 -46
- data/src/DirectoriesWin.cpp +0 -65
- data/src/EmptyImageData.hpp +0 -52
- data/src/FileUnix.cpp +0 -99
- data/src/FileWin.cpp +0 -88
- data/src/IO.cpp +0 -60
- data/src/Iconv.hpp +0 -51
- data/src/Inspection.cpp +0 -27
- data/src/LargeImageData.cpp +0 -215
- data/src/LargeImageData.hpp +0 -39
- data/src/Log.hpp +0 -19
- data/src/RubyGosu.cxx +0 -13100
- data/src/RubyGosu.h +0 -49
- data/src/WinUtility.cpp +0 -61
- data/src/WinUtility.hpp +0 -27
- /data/dependencies/SDL/include/{SDL_opengles2_gl2.h → SDL3/SDL_opengles2_gl2.h} +0 -0
- /data/dependencies/SDL/include/{SDL_opengles2_gl2ext.h → SDL3/SDL_opengles2_gl2ext.h} +0 -0
- /data/dependencies/SDL/include/{SDL_opengles2_gl2platform.h → SDL3/SDL_opengles2_gl2platform.h} +0 -0
- /data/dependencies/SDL/include/{SDL_opengles2_khrplatform.h → SDL3/SDL_opengles2_khrplatform.h} +0 -0
data/src/Macro.cpp
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#include <Gosu/Image.hpp>
|
|
3
3
|
#include <Gosu/Utility.hpp>
|
|
4
4
|
#include "DrawOpQueue.hpp"
|
|
5
|
+
#include <optional>
|
|
5
6
|
#include <stdexcept>
|
|
6
7
|
|
|
7
8
|
struct Gosu::Macro::Impl : private Gosu::Noncopyable
|
|
@@ -17,14 +18,16 @@ struct Gosu::Macro::Impl : private Gosu::Noncopyable
|
|
|
17
18
|
double b1, double b2, double& x1, double& x2)
|
|
18
19
|
{
|
|
19
20
|
const double det = a11 * a22 - a21 * a12;
|
|
20
|
-
if (det == 0)
|
|
21
|
+
if (det == 0) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
21
24
|
x1 = (a22 * b1 - a12 * b2) / det;
|
|
22
25
|
x2 = (a11 * b2 - a21 * b1) / det;
|
|
23
26
|
return true;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
Transform
|
|
27
|
-
|
|
29
|
+
std::optional<Transform> find_transform(double x1, double y1, double x2, double y2, //
|
|
30
|
+
double x3, double y3, double x4, double y4) const
|
|
28
31
|
{
|
|
29
32
|
// Transformation logic follows a discussion on the ImageMagick mailing
|
|
30
33
|
// list (on which ImageMagick's perspective_transform.pl is based).
|
|
@@ -64,7 +67,9 @@ struct Gosu::Macro::Impl : private Gosu::Noncopyable
|
|
|
64
67
|
|
|
65
68
|
// Solve:
|
|
66
69
|
double qx, qy;
|
|
67
|
-
if (!solve_2x2(a11, a12, a21, a22, b1, b2, qx, qy))
|
|
70
|
+
if (!solve_2x2(a11, a12, a21, a22, b1, b2, qx, qy)) {
|
|
71
|
+
return std::nullopt;
|
|
72
|
+
}
|
|
68
73
|
|
|
69
74
|
// Updating the last two rows with the computed solution yields
|
|
70
75
|
|
|
@@ -88,7 +93,7 @@ struct Gosu::Macro::Impl : private Gosu::Noncopyable
|
|
|
88
93
|
// 0, 0, 0, 0, 0, 0, 1, 0 | qx
|
|
89
94
|
// 0, 0, 0, 0, 0, 0, 0, 1 | qy
|
|
90
95
|
|
|
91
|
-
// Normalize and reorder rows so we can read off the solution:
|
|
96
|
+
// Normalize and reorder rows, so we can read off the solution:
|
|
92
97
|
|
|
93
98
|
// 1, 0, 0, 0, 0, 0, 0, 0 | (x2-x1) / w + qx x2
|
|
94
99
|
// 0, 1, 0, 0, 0, 0, 0, 0 | (x3-x1) / h + qy x3
|
|
@@ -109,10 +114,10 @@ struct Gosu::Macro::Impl : private Gosu::Noncopyable
|
|
|
109
114
|
c[6] = qx;
|
|
110
115
|
c[7] = qy;
|
|
111
116
|
|
|
112
|
-
Transform result = {{c[0], c[3], 0, c[6], //
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
Transform result = { { c[0], c[3], 0, c[6], //
|
|
118
|
+
c[1], c[4], 0, c[7], //
|
|
119
|
+
0, 0, 1, 0, //
|
|
120
|
+
c[2], c[5], 0, 1 } };
|
|
116
121
|
return result;
|
|
117
122
|
}
|
|
118
123
|
|
|
@@ -124,29 +129,35 @@ struct Gosu::Macro::Impl : private Gosu::Noncopyable
|
|
|
124
129
|
// transformation only has to be performed once.
|
|
125
130
|
|
|
126
131
|
#ifndef GOSU_IS_OPENGLES
|
|
132
|
+
const std::optional<Transform> transform
|
|
133
|
+
= find_transform(x1, y1, x2, y2, x3, y3, x4, y4);
|
|
134
|
+
if (!transform.has_value()) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
127
138
|
glEnable(GL_BLEND);
|
|
128
139
|
glMatrixMode(GL_MODELVIEW);
|
|
129
140
|
|
|
130
|
-
Transform transform = find_transform_for_target(x1, y1, x2, y2, x3, y3, x4, y4);
|
|
131
|
-
|
|
132
141
|
for (const auto& vertex_array : vertex_arrays) {
|
|
133
142
|
glPushMatrix();
|
|
143
|
+
const auto pop_matrix = finally([] { glPopMatrix(); });
|
|
144
|
+
|
|
134
145
|
vertex_array.render_state.apply();
|
|
135
|
-
glMultMatrixd(
|
|
136
|
-
glInterleavedArrays(GL_T2F_C4UB_V3F, 0,
|
|
137
|
-
glDrawArrays(GL_QUADS, 0, (GLsizei)
|
|
138
|
-
glPopMatrix();
|
|
146
|
+
glMultMatrixd(transform->matrix.data());
|
|
147
|
+
glInterleavedArrays(GL_T2F_C4UB_V3F, 0, vertex_array.vertices.data());
|
|
148
|
+
glDrawArrays(GL_QUADS, 0, (GLsizei)vertex_array.vertices.size());
|
|
139
149
|
}
|
|
140
150
|
#endif
|
|
141
151
|
}
|
|
142
152
|
};
|
|
143
153
|
|
|
144
154
|
Gosu::Macro::Macro(DrawOpQueue& queue, int width, int height)
|
|
145
|
-
: pimpl(new Impl)
|
|
146
155
|
{
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
156
|
+
auto impl = std::make_shared<Impl>();
|
|
157
|
+
impl->width = width;
|
|
158
|
+
impl->height = height;
|
|
159
|
+
queue.compile_to(impl->vertex_arrays);
|
|
160
|
+
pimpl = std::move(impl);
|
|
150
161
|
}
|
|
151
162
|
|
|
152
163
|
int Gosu::Macro::width() const
|
|
@@ -161,15 +172,17 @@ int Gosu::Macro::height() const
|
|
|
161
172
|
|
|
162
173
|
void Gosu::Macro::draw(double x1, double y1, Color c1, double x2, double y2, Color c2, //
|
|
163
174
|
double x3, double y3, Color c3, double x4, double y4, Color c4, //
|
|
164
|
-
ZPos z, BlendMode
|
|
175
|
+
ZPos z, BlendMode) const
|
|
165
176
|
{
|
|
166
177
|
if (c1 != Color::WHITE || c2 != Color::WHITE || c3 != Color::WHITE || c4 != Color::WHITE) {
|
|
167
|
-
throw std::invalid_argument
|
|
178
|
+
throw std::invalid_argument("Macros cannot be tinted with colors");
|
|
168
179
|
}
|
|
169
180
|
|
|
170
181
|
normalize_coordinates(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
|
|
171
182
|
|
|
172
|
-
|
|
183
|
+
// Capture pimpl, not this: The GL block only runs when the queue is flushed, and this Macro
|
|
184
|
+
// may have been destroyed by then.
|
|
185
|
+
gl(z, [=, impl = pimpl] { impl->draw_vertex_arrays(x1, y1, x2, y2, x3, y3, x4, y4); });
|
|
173
186
|
}
|
|
174
187
|
|
|
175
188
|
const Gosu::GLTexInfo* Gosu::Macro::gl_tex_info() const
|
|
@@ -179,20 +192,24 @@ const Gosu::GLTexInfo* Gosu::Macro::gl_tex_info() const
|
|
|
179
192
|
|
|
180
193
|
Gosu::Bitmap Gosu::Macro::to_bitmap() const
|
|
181
194
|
{
|
|
195
|
+
Viewport viewport(pimpl->width, pimpl->height);
|
|
196
|
+
const auto current = viewport.make_current();
|
|
197
|
+
|
|
182
198
|
const auto render_this = [this] {
|
|
183
|
-
draw(0, 0, Color::WHITE, pimpl->width, 0, Color::WHITE,
|
|
184
|
-
pimpl->width, pimpl->height, Color::WHITE,
|
|
199
|
+
draw(0, 0, Color::WHITE, pimpl->width, 0, Color::WHITE, //
|
|
200
|
+
0, pimpl->height, Color::WHITE, pimpl->width, pimpl->height, Color::WHITE, //
|
|
201
|
+
0, BM_DEFAULT);
|
|
185
202
|
};
|
|
186
203
|
|
|
187
|
-
return
|
|
204
|
+
return render(pimpl->width, pimpl->height, render_this).drawable().to_bitmap();
|
|
188
205
|
}
|
|
189
206
|
|
|
190
|
-
std::unique_ptr<Gosu::
|
|
207
|
+
std::unique_ptr<Gosu::Drawable> Gosu::Macro::subimage(const Rect&) const
|
|
191
208
|
{
|
|
192
|
-
return
|
|
209
|
+
return nullptr;
|
|
193
210
|
}
|
|
194
211
|
|
|
195
|
-
void Gosu::Macro::insert(const Bitmap
|
|
212
|
+
void Gosu::Macro::insert(const Bitmap&, int, int)
|
|
196
213
|
{
|
|
197
|
-
throw std::logic_error
|
|
214
|
+
throw std::logic_error("Gosu::Macro cannot be updated with a Gosu::Bitmap yet");
|
|
198
215
|
}
|
data/src/Macro.hpp
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
3
|
#include <Gosu/Fwd.hpp>
|
|
4
|
-
#include <Gosu/
|
|
5
|
-
#include "GraphicsImpl.hpp"
|
|
4
|
+
#include <Gosu/Drawable.hpp>
|
|
6
5
|
#include <memory>
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
namespace Gosu
|
|
9
8
|
{
|
|
10
|
-
|
|
11
|
-
std::shared_ptr<Impl> pimpl;
|
|
9
|
+
class DrawOpQueue;
|
|
12
10
|
|
|
13
|
-
public
|
|
14
|
-
|
|
11
|
+
class Macro : public Drawable
|
|
12
|
+
{
|
|
13
|
+
// This is a shared_ptr so that enqueued DrawOps can keep the macro data alive even after
|
|
14
|
+
// the Macro object itself has been destroyed.
|
|
15
|
+
struct Impl;
|
|
16
|
+
std::shared_ptr<const Impl> pimpl;
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
public:
|
|
19
|
+
Macro(DrawOpQueue& queue, int width, int height);
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
ZPos z, BlendMode mode) const override;
|
|
21
|
+
int width() const override;
|
|
22
|
+
int height() const override;
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
void draw(double x1, double y1, Color c1, double x2, double y2, Color c2, //
|
|
25
|
+
double x3, double y3, Color c3, double x4, double y4, Color c4, //
|
|
26
|
+
ZPos z, BlendMode mode) const override;
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
const GLTexInfo* gl_tex_info() const override;
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
Bitmap to_bitmap() const override;
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
std::unique_ptr<Drawable> subimage(const Rect&) const override;
|
|
33
|
+
|
|
34
|
+
void insert(const Bitmap&, int x, int y) override;
|
|
35
|
+
};
|
|
36
|
+
}
|
data/src/MarkupParser.cpp
CHANGED
|
@@ -157,29 +157,29 @@ void Gosu::MarkupParser::add_current_substring()
|
|
|
157
157
|
void Gosu::MarkupParser::add_composed_substring(u32string&& substring)
|
|
158
158
|
{
|
|
159
159
|
FormattedString fstr;
|
|
160
|
-
fstr.text = substring;
|
|
160
|
+
fstr.text = std::move(substring);
|
|
161
161
|
fstr.flags = flags();
|
|
162
162
|
fstr.color = c.back();
|
|
163
163
|
|
|
164
164
|
if (!substrings.empty() && substrings.back().can_be_merged_with(fstr)) {
|
|
165
|
-
substrings.back().text.append(
|
|
165
|
+
substrings.back().text.append(fstr.text);
|
|
166
166
|
}
|
|
167
167
|
else {
|
|
168
|
-
substrings.emplace_back(move(fstr));
|
|
168
|
+
substrings.emplace_back(std::move(fstr));
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
void Gosu::MarkupParser::flush_to_consumer()
|
|
173
173
|
{
|
|
174
174
|
if (!substrings.empty()) {
|
|
175
|
-
consumer(move(substrings));
|
|
175
|
+
consumer(std::move(substrings));
|
|
176
176
|
substrings.clear();
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
Gosu::MarkupParser::MarkupParser(unsigned base_flags, bool split_words,
|
|
181
181
|
function<void (vector<FormattedString>)> consumer)
|
|
182
|
-
: consumer(move(consumer))
|
|
182
|
+
: consumer(std::move(consumer))
|
|
183
183
|
{
|
|
184
184
|
word_state = (split_words ? ADDING_WORD : IGNORE_WORDS);
|
|
185
185
|
|
data/src/Math.cpp
CHANGED
|
@@ -1,38 +1,57 @@
|
|
|
1
1
|
#include <Gosu/Math.hpp>
|
|
2
|
-
#include <
|
|
3
|
-
|
|
2
|
+
#include <algorithm>
|
|
3
|
+
#include <cmath>
|
|
4
|
+
#include <limits> // for std::numeric_limits::quiet_NaN
|
|
5
|
+
#include <random>
|
|
6
|
+
#include <stdexcept>
|
|
4
7
|
|
|
5
8
|
double Gosu::random(double min, double max)
|
|
6
9
|
{
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
if (!std::isfinite(min) || !std::isfinite(max)) {
|
|
11
|
+
return std::numeric_limits<double>::quiet_NaN();
|
|
12
|
+
}
|
|
13
|
+
if (min >= max) {
|
|
14
|
+
throw std::invalid_argument("Gosu::random: min >= max");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
thread_local std::mt19937_64 generator(std::random_device { }());
|
|
18
|
+
std::uniform_real_distribution<double> distribution(min, max);
|
|
19
|
+
const double result = distribution(generator);
|
|
20
|
+
|
|
21
|
+
// Make sure that we do not return "max" even when uniform_real_distribution is buggy.
|
|
22
|
+
// See "Notes": https://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution
|
|
23
|
+
return result == max ? min : result;
|
|
9
24
|
}
|
|
10
25
|
|
|
11
26
|
double Gosu::offset_x(double angle, double radius)
|
|
12
27
|
{
|
|
13
|
-
return +sin(angle
|
|
28
|
+
return +std::sin(degrees_to_radians(angle)) * radius;
|
|
14
29
|
}
|
|
15
30
|
|
|
16
31
|
double Gosu::offset_y(double angle, double radius)
|
|
17
32
|
{
|
|
18
|
-
return -cos(angle
|
|
33
|
+
return -std::cos(degrees_to_radians(angle)) * radius;
|
|
19
34
|
}
|
|
20
35
|
|
|
21
|
-
double Gosu::angle(double from_x, double from_y, double to_x, double to_y, double
|
|
36
|
+
double Gosu::angle(double from_x, double from_y, double to_x, double to_y, double fallback)
|
|
22
37
|
{
|
|
23
38
|
double dist_x = to_x - from_x;
|
|
24
39
|
double dist_y = to_y - from_y;
|
|
25
40
|
|
|
41
|
+
// Special-case the four cardinal directions values so that we don't run into subtle rounding
|
|
42
|
+
// errors for these obvious values.
|
|
26
43
|
if (dist_x == 0) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
if (dist_y == 0) {
|
|
45
|
+
return fallback;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return dist_y < 0 ? 0 : 180;
|
|
49
|
+
}
|
|
50
|
+
else if (dist_y == 0) {
|
|
51
|
+
return dist_x < 0 ? 270 : 90;
|
|
33
52
|
}
|
|
34
53
|
|
|
35
|
-
return normalize_angle(
|
|
54
|
+
return normalize_angle(radians_to_angle(std::atan2(dist_y, dist_x)));
|
|
36
55
|
}
|
|
37
56
|
|
|
38
57
|
double Gosu::angle_diff(double from, double to)
|
|
@@ -47,23 +66,30 @@ double Gosu::normalize_angle(double angle)
|
|
|
47
66
|
|
|
48
67
|
int Gosu::wrap(int value, int min, int max)
|
|
49
68
|
{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
69
|
+
if (min >= max) {
|
|
70
|
+
throw std::invalid_argument("Gosu::wrap: min >= max");
|
|
71
|
+
}
|
|
53
72
|
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
float result = fmodf(value - min, max - min);
|
|
73
|
+
int result = (value - min) % (max - min);
|
|
57
74
|
return result < 0 ? result + max : result + min;
|
|
58
75
|
}
|
|
59
76
|
|
|
60
77
|
double Gosu::wrap(double value, double min, double max)
|
|
61
78
|
{
|
|
62
|
-
|
|
79
|
+
if (!std::isfinite(value) || !std::isfinite(min) || !std::isfinite(max)) {
|
|
80
|
+
return std::numeric_limits<double>::quiet_NaN();
|
|
81
|
+
}
|
|
82
|
+
if (min >= max) {
|
|
83
|
+
throw std::invalid_argument("Gosu::wrap: min >= max");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
double result = std::fmod(value - min, max - min);
|
|
63
87
|
return result < 0 ? result + max : result + min;
|
|
64
88
|
}
|
|
65
89
|
|
|
66
90
|
double Gosu::distance(double x1, double y1, double x2, double y2)
|
|
67
91
|
{
|
|
68
|
-
|
|
92
|
+
double dist_x = (x2 - x1);
|
|
93
|
+
double dist_y = (y2 - y1);
|
|
94
|
+
return std::sqrt(dist_x * dist_x + dist_y * dist_y);
|
|
69
95
|
}
|
data/src/OffScreenTarget.cpp
CHANGED
|
@@ -1,99 +1,96 @@
|
|
|
1
1
|
#include "OffScreenTarget.hpp"
|
|
2
|
-
#include "Texture.hpp"
|
|
3
2
|
#include <Gosu/Image.hpp>
|
|
4
3
|
#include <Gosu/Platform.hpp>
|
|
4
|
+
#include "OpenGLContext.hpp"
|
|
5
|
+
#include "Texture.hpp"
|
|
5
6
|
#ifndef GOSU_IS_IPHONE
|
|
6
|
-
#include <SDL.h>
|
|
7
|
+
#include <SDL3/SDL.h> // for SDL_GL_GetProcAddress
|
|
7
8
|
#endif
|
|
8
|
-
using namespace std;
|
|
9
9
|
|
|
10
10
|
#ifdef GOSU_IS_OPENGLES
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
#define GOSU_GL_CONST(name) \
|
|
15
|
-
name ## _OES
|
|
16
|
-
|
|
17
|
-
#define GOSU_GL_DEPTH_COMPONENT \
|
|
18
|
-
GL_DEPTH_COMPONENT16_OES
|
|
11
|
+
#define GOSU_LOAD_GL_EXT(fn, type) static auto fn = fn##OES
|
|
12
|
+
#define GOSU_GL_CONST(name) name##_OES
|
|
13
|
+
#define GOSU_GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT16_OES
|
|
19
14
|
#else
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#define GOSU_GL_DEPTH_COMPONENT \
|
|
28
|
-
GL_DEPTH_COMPONENT
|
|
15
|
+
#define GOSU_LOAD_GL_EXT(fn, type) \
|
|
16
|
+
static auto fn = reinterpret_cast<type>(SDL_GL_GetProcAddress(#fn)); \
|
|
17
|
+
if ((fn) == nullptr) { \
|
|
18
|
+
throw std::runtime_error("Unable to load " #fn); \
|
|
19
|
+
}
|
|
20
|
+
#define GOSU_GL_CONST(name) name
|
|
21
|
+
#define GOSU_GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT
|
|
29
22
|
#endif
|
|
30
23
|
|
|
31
24
|
Gosu::OffScreenTarget::OffScreenTarget(int width, int height, unsigned image_flags)
|
|
25
|
+
: r_renderbuffer(static_cast<GLuint>(-1)),
|
|
26
|
+
m_framebuffer(static_cast<GLuint>(-1))
|
|
32
27
|
{
|
|
33
28
|
#ifndef GOSU_IS_IPHONE
|
|
29
|
+
// GCOV_EXCL_START
|
|
34
30
|
if (!SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object")) {
|
|
35
|
-
throw runtime_error("Missing GL_EXT_framebuffer_object extension");
|
|
31
|
+
throw std::runtime_error("Missing GL_EXT_framebuffer_object extension");
|
|
36
32
|
}
|
|
33
|
+
// GCOV_EXCL_end
|
|
37
34
|
#endif
|
|
38
|
-
|
|
35
|
+
|
|
39
36
|
// Create a new texture that will be our rendering target.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
texture->block(0, 0, width, height);
|
|
43
|
-
|
|
37
|
+
m_texture = std::make_shared<Texture>(width, height, image_flags & IF_RETRO);
|
|
38
|
+
|
|
44
39
|
// Besides the texture, also create a renderbuffer for depth information.
|
|
45
|
-
// Gosu doesn't use this, but custom OpenGL code
|
|
40
|
+
// Gosu doesn't use this, but custom OpenGL code might.
|
|
46
41
|
GOSU_LOAD_GL_EXT(glGenRenderbuffers, PFNGLGENRENDERBUFFERSPROC);
|
|
47
|
-
glGenRenderbuffers(1, &
|
|
48
|
-
|
|
42
|
+
glGenRenderbuffers(1, &r_renderbuffer);
|
|
43
|
+
|
|
49
44
|
GOSU_LOAD_GL_EXT(glBindRenderbuffer, PFNGLBINDRENDERBUFFERPROC);
|
|
50
|
-
glBindRenderbuffer(GOSU_GL_CONST(GL_RENDERBUFFER),
|
|
51
|
-
|
|
45
|
+
glBindRenderbuffer(GOSU_GL_CONST(GL_RENDERBUFFER), r_renderbuffer);
|
|
46
|
+
|
|
52
47
|
GOSU_LOAD_GL_EXT(glRenderbufferStorage, PFNGLRENDERBUFFERSTORAGEPROC);
|
|
53
48
|
glRenderbufferStorage(GOSU_GL_CONST(GL_RENDERBUFFER), GOSU_GL_DEPTH_COMPONENT, width, height);
|
|
54
49
|
glBindRenderbuffer(GOSU_GL_CONST(GL_RENDERBUFFER), 0);
|
|
55
|
-
|
|
50
|
+
|
|
56
51
|
// Now tie everything together.
|
|
57
52
|
GOSU_LOAD_GL_EXT(glGenFramebuffers, PFNGLGENFRAMEBUFFERSPROC);
|
|
58
|
-
glGenFramebuffers(1, &
|
|
59
|
-
|
|
53
|
+
glGenFramebuffers(1, &m_framebuffer);
|
|
54
|
+
|
|
60
55
|
GOSU_LOAD_GL_EXT(glBindFramebuffer, PFNGLBINDFRAMEBUFFERPROC);
|
|
61
|
-
glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER),
|
|
62
|
-
|
|
56
|
+
glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), m_framebuffer);
|
|
57
|
+
|
|
63
58
|
GOSU_LOAD_GL_EXT(glFramebufferTexture2D, PFNGLFRAMEBUFFERTEXTURE2DPROC);
|
|
64
59
|
glFramebufferTexture2D(GOSU_GL_CONST(GL_FRAMEBUFFER), GOSU_GL_CONST(GL_COLOR_ATTACHMENT0),
|
|
65
|
-
GL_TEXTURE_2D,
|
|
66
|
-
|
|
60
|
+
GL_TEXTURE_2D, m_texture->tex_name(), 0);
|
|
61
|
+
|
|
67
62
|
GOSU_LOAD_GL_EXT(glFramebufferRenderbuffer, PFNGLFRAMEBUFFERRENDERBUFFERPROC);
|
|
68
63
|
glFramebufferRenderbuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), GOSU_GL_CONST(GL_DEPTH_ATTACHMENT),
|
|
69
|
-
GOSU_GL_CONST(GL_RENDERBUFFER),
|
|
64
|
+
GOSU_GL_CONST(GL_RENDERBUFFER), r_renderbuffer);
|
|
70
65
|
}
|
|
71
66
|
|
|
72
67
|
Gosu::OffScreenTarget::~OffScreenTarget()
|
|
73
68
|
{
|
|
74
69
|
try {
|
|
75
70
|
GOSU_LOAD_GL_EXT(glDeleteRenderbuffers, PFNGLDELETERENDERBUFFERSPROC);
|
|
76
|
-
glDeleteRenderbuffers(1, &
|
|
77
|
-
|
|
71
|
+
glDeleteRenderbuffers(1, &r_renderbuffer);
|
|
72
|
+
|
|
78
73
|
GOSU_LOAD_GL_EXT(glDeleteFramebuffers, PFNGLDELETEFRAMEBUFFERSPROC);
|
|
79
|
-
glDeleteFramebuffers(1, &
|
|
74
|
+
glDeleteFramebuffers(1, &m_framebuffer);
|
|
75
|
+
// GCOV_EXCL_START
|
|
80
76
|
} catch (...) {
|
|
81
77
|
// If we can't load these functions, just accept the resource leak.
|
|
82
78
|
}
|
|
79
|
+
// GCOV_EXCL_END
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
Gosu::Image Gosu::OffScreenTarget::render(const std::function<void ()>& f)
|
|
86
83
|
{
|
|
87
84
|
GOSU_LOAD_GL_EXT(glBindFramebuffer, PFNGLBINDFRAMEBUFFERPROC);
|
|
88
|
-
glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER),
|
|
89
|
-
|
|
85
|
+
glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), m_framebuffer);
|
|
86
|
+
|
|
90
87
|
GOSU_LOAD_GL_EXT(glCheckFramebufferStatus, PFNGLCHECKFRAMEBUFFERSTATUSPROC);
|
|
91
88
|
GLenum status = glCheckFramebufferStatus(GOSU_GL_CONST(GL_FRAMEBUFFER));
|
|
92
|
-
if (status != GOSU_GL_CONST(GL_FRAMEBUFFER_COMPLETE))
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), 0);
|
|
89
|
+
if (status != GOSU_GL_CONST(GL_FRAMEBUFFER_COMPLETE)) {
|
|
90
|
+
throw std::runtime_error("Incomplete framebuffer");
|
|
91
|
+
}
|
|
96
92
|
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
auto reset_framebuffer = finally([] { glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), 0); });
|
|
94
|
+
f();
|
|
95
|
+
return Image(std::make_unique<TexChunk>(m_texture, Rect::covering(*m_texture), nullptr));
|
|
99
96
|
}
|
data/src/OffScreenTarget.hpp
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include
|
|
3
|
+
#include <Gosu/Utility.hpp>
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
#include <functional>
|
|
6
|
+
#include <memory>
|
|
4
7
|
|
|
5
8
|
namespace Gosu
|
|
6
9
|
{
|
|
7
|
-
class
|
|
10
|
+
class Image;
|
|
11
|
+
class Texture;
|
|
12
|
+
|
|
13
|
+
class OffScreenTarget : private Noncopyable
|
|
8
14
|
{
|
|
9
|
-
std::shared_ptr<Texture>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
OffScreenTarget(const OffScreenTarget& other) = delete;
|
|
14
|
-
OffScreenTarget& operator=(const OffScreenTarget& other) = delete;
|
|
15
|
-
OffScreenTarget(OffScreenTarget&& other) = delete;
|
|
16
|
-
OffScreenTarget& operator=(OffScreenTarget&& other) = delete;
|
|
17
|
-
|
|
15
|
+
std::shared_ptr<Texture> m_texture;
|
|
16
|
+
std::uint32_t r_renderbuffer;
|
|
17
|
+
std::uint32_t m_framebuffer;
|
|
18
|
+
|
|
18
19
|
public:
|
|
19
20
|
OffScreenTarget(int width, int height, unsigned image_flags);
|
|
20
21
|
~OffScreenTarget();
|
|
22
|
+
|
|
21
23
|
Gosu::Image render(const std::function<void ()>& f);
|
|
22
24
|
};
|
|
23
25
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#include "OpenGLContext.hpp"
|
|
2
|
+
#if !defined(GOSU_IS_IPHONE) // on iPhone, GosuGLView.cpp implements OpenGLContext.
|
|
3
|
+
|
|
4
|
+
#if defined(GOSU_IS_MAC)
|
|
5
|
+
#include <Foundation/Foundation.h> // for -[NSThread isMainThread]
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#include <stdexcept>
|
|
9
|
+
#include <thread>
|
|
10
|
+
|
|
11
|
+
namespace
|
|
12
|
+
{
|
|
13
|
+
[[noreturn]] void throw_sdl_error(const std::string& operation)
|
|
14
|
+
{
|
|
15
|
+
throw std::runtime_error(operation + ": " + SDL_GetError());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// Groups the global SDL variables into a single struct so that they all either exist, or not.
|
|
19
|
+
struct SDLWindowAndGLContext : Gosu::Noncopyable
|
|
20
|
+
{
|
|
21
|
+
SDL_Window* window;
|
|
22
|
+
/// We only use one OpenGL context, even from background threads. It would be possible to
|
|
23
|
+
/// set up shared OpenGL contexts here (c.f. git history of this file), but according to
|
|
24
|
+
/// various sources on the internet, sharing OpenGL contexts does not help performance.
|
|
25
|
+
/// https://discourse.libsdl.org/t/feasibility-correctness-of-calling-gl-in-another-thread/20292/6
|
|
26
|
+
SDL_GLContext gl_context;
|
|
27
|
+
|
|
28
|
+
SDLWindowAndGLContext()
|
|
29
|
+
{
|
|
30
|
+
static const int initialized = SDL_Init(SDL_INIT_VIDEO);
|
|
31
|
+
if (initialized < 0) {
|
|
32
|
+
throw_sdl_error("Could not initialize SDL");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#ifdef GOSU_IS_MAC
|
|
36
|
+
if (![NSThread isMainThread]) {
|
|
37
|
+
throw std::logic_error("Gosu::Window/OpenGL must be initialized on main thread");
|
|
38
|
+
}
|
|
39
|
+
#endif
|
|
40
|
+
#ifdef GOSU_IS_OPENGLES
|
|
41
|
+
// We want to use OpenGL ES 1.1, which does not yet require us to use shaders.
|
|
42
|
+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
|
|
43
|
+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
window = //
|
|
47
|
+
SDL_CreateWindow("", 64, 64,
|
|
48
|
+
SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN
|
|
49
|
+
| SDL_WINDOW_HIGH_PIXEL_DENSITY);
|
|
50
|
+
if (!window) {
|
|
51
|
+
throw_sdl_error("Could not create SDL window");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
gl_context = SDL_GL_CreateContext(window);
|
|
55
|
+
if (!gl_context) {
|
|
56
|
+
SDL_DestroyWindow(window);
|
|
57
|
+
throw_sdl_error("Could not create main OpenGL context");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static SDLWindowAndGLContext& instance()
|
|
62
|
+
{
|
|
63
|
+
static SDLWindowAndGLContext instance;
|
|
64
|
+
return instance;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/// The current nesting level of OpenGLContext objects.
|
|
69
|
+
thread_local int current_nesting_depth = 0; // NOLINT(*-avoid-non-const-global-variables)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Gosu::OpenGLContext::OpenGLContext(bool for_rendering_to_window)
|
|
73
|
+
{
|
|
74
|
+
static const auto& window = SDLWindowAndGLContext::instance();
|
|
75
|
+
|
|
76
|
+
// All threads use a single mutex to coordinate access to their OpenGL context.
|
|
77
|
+
static std::mutex mutex;
|
|
78
|
+
if (current_nesting_depth == 0) {
|
|
79
|
+
// ...but only the innermost OpenGLContext in a thread owns the lock.
|
|
80
|
+
m_lock = std::unique_lock(mutex);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Explicitly make the context current every time for_rendering_to_window is set, so that we set
|
|
84
|
+
// the current SDL_Window even if we are somehow nested into something else.
|
|
85
|
+
if (for_rendering_to_window) {
|
|
86
|
+
if (!SDL_GL_MakeCurrent(window.window, window.gl_context)) {
|
|
87
|
+
throw_sdl_error("Could not set current GL context for rendering to the window");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (current_nesting_depth == 0) {
|
|
91
|
+
// On other platforms, make the context current together with its (hidden) window.
|
|
92
|
+
// A context without a Window is broken under Linux with SDL3 (cannot find extensions).
|
|
93
|
+
if (!SDL_GL_MakeCurrent(window.window, window.gl_context)) {
|
|
94
|
+
throw_sdl_error("Could not set current GL context");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
++current_nesting_depth;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
Gosu::OpenGLContext::~OpenGLContext()
|
|
102
|
+
{
|
|
103
|
+
--current_nesting_depth;
|
|
104
|
+
|
|
105
|
+
if (m_lock) {
|
|
106
|
+
SDL_GL_MakeCurrent(nullptr, nullptr);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
SDL_Window* Gosu::OpenGLContext::shared_sdl_window()
|
|
111
|
+
{
|
|
112
|
+
static const auto& window = SDLWindowAndGLContext::instance();
|
|
113
|
+
return window.window;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#endif
|