gosu 1.4.6 → 2.0.0.pre7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +2 -1
  3. data/dependencies/SDL/include/SDL_assert.h +2 -0
  4. data/dependencies/SDL/include/SDL_atomic.h +2 -3
  5. data/dependencies/SDL/include/SDL_audio.h +7 -7
  6. data/dependencies/SDL/include/SDL_blendmode.h +1 -1
  7. data/dependencies/SDL/include/SDL_endian.h +3 -3
  8. data/dependencies/SDL/include/SDL_gamecontroller.h +4 -4
  9. data/dependencies/SDL/include/SDL_hints.h +83 -28
  10. data/dependencies/SDL/include/SDL_joystick.h +8 -5
  11. data/dependencies/SDL/include/SDL_keycode.h +1 -1
  12. data/dependencies/SDL/include/SDL_main.h +7 -0
  13. data/dependencies/SDL/include/SDL_mouse.h +6 -7
  14. data/dependencies/SDL/include/SDL_mutex.h +79 -5
  15. data/dependencies/SDL/include/SDL_opengl_glext.h +5 -1
  16. data/dependencies/SDL/include/SDL_power.h +7 -8
  17. data/dependencies/SDL/include/SDL_render.h +6 -1
  18. data/dependencies/SDL/include/SDL_revision.h +2 -2
  19. data/dependencies/SDL/include/SDL_sensor.h +1 -1
  20. data/dependencies/SDL/include/SDL_stdinc.h +19 -11
  21. data/dependencies/SDL/include/SDL_thread.h +2 -2
  22. data/dependencies/SDL/include/SDL_version.h +2 -2
  23. data/dependencies/SDL/include/SDL_video.h +30 -2
  24. data/dependencies/SDL/include/begin_code.h +7 -7
  25. data/dependencies/SDL/include/close_code.h +2 -2
  26. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  27. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  28. data/dependencies/SDL_sound/SDL_sound.h +1 -1
  29. data/dependencies/SDL_sound/dr_flac.h +48 -23
  30. data/dependencies/SDL_sound/dr_mp3.h +34 -14
  31. data/dependencies/SDL_sound/stb_vorbis.h +3 -2
  32. data/dependencies/mojoAL/mojoal.c +1 -1
  33. data/ext/{gosu → gosu-ffi}/extconf.rb +34 -33
  34. data/ext/gosu-ffi/gosu-ffi.def +465 -0
  35. data/ffi/Gosu.cpp +307 -0
  36. data/ffi/Gosu.h +84 -0
  37. data/ffi/Gosu_Channel.cpp +62 -0
  38. data/ffi/Gosu_Channel.h +17 -0
  39. data/ffi/Gosu_Color.cpp +132 -0
  40. data/ffi/Gosu_Color.h +31 -0
  41. data/ffi/Gosu_Constants.cpp +334 -0
  42. data/ffi/Gosu_FFI.h +34 -0
  43. data/ffi/Gosu_FFI_internal.h +161 -0
  44. data/ffi/Gosu_Font.cpp +92 -0
  45. data/ffi/Gosu_Font.h +32 -0
  46. data/ffi/Gosu_Image.cpp +218 -0
  47. data/ffi/Gosu_Image.h +66 -0
  48. data/ffi/Gosu_Sample.cpp +29 -0
  49. data/ffi/Gosu_Sample.h +14 -0
  50. data/ffi/Gosu_Song.cpp +69 -0
  51. data/ffi/Gosu_Song.h +18 -0
  52. data/ffi/Gosu_TextInput.cpp +94 -0
  53. data/ffi/Gosu_TextInput.h +25 -0
  54. data/ffi/Gosu_Window.cpp +314 -0
  55. data/ffi/Gosu_Window.h +78 -0
  56. data/include/Gosu/Audio.hpp +6 -11
  57. data/include/Gosu/Bitmap.hpp +38 -53
  58. data/include/Gosu/Buffer.hpp +54 -0
  59. data/include/Gosu/Color.hpp +27 -35
  60. data/include/Gosu/Directories.hpp +25 -28
  61. data/include/Gosu/Drawable.hpp +58 -0
  62. data/include/Gosu/Font.hpp +6 -5
  63. data/include/Gosu/Fwd.hpp +4 -6
  64. data/include/Gosu/Gosu.hpp +5 -5
  65. data/include/Gosu/Graphics.hpp +51 -61
  66. data/include/Gosu/GraphicsBase.hpp +1 -11
  67. data/include/Gosu/Image.hpp +12 -15
  68. data/include/Gosu/Math.hpp +50 -72
  69. data/include/Gosu/Transform.hpp +32 -0
  70. data/include/Gosu/Utility.hpp +51 -1
  71. data/include/Gosu/Version.hpp +3 -3
  72. data/include/Gosu/Window.hpp +15 -9
  73. data/lib/SDL2.dll +0 -0
  74. data/lib/gosu/channel.rb +49 -0
  75. data/lib/gosu/color.rb +150 -0
  76. data/lib/gosu/compat.rb +29 -8
  77. data/lib/gosu/constants.rb +386 -0
  78. data/lib/gosu/ffi.rb +259 -0
  79. data/lib/gosu/font.rb +56 -0
  80. data/lib/gosu/gl_tex_info.rb +33 -0
  81. data/lib/gosu/gosu.rb +210 -0
  82. data/lib/gosu/image.rb +153 -0
  83. data/lib/gosu/numeric.rb +17 -0
  84. data/lib/gosu/preview.rb +6 -6
  85. data/lib/gosu/sample.rb +24 -0
  86. data/lib/gosu/song.rb +56 -0
  87. data/lib/gosu/text_input.rb +69 -0
  88. data/lib/gosu/window.rb +228 -0
  89. data/lib/gosu.rb +29 -8
  90. data/lib64/SDL2.dll +0 -0
  91. data/rdoc/gosu.rb +0 -2
  92. data/src/Audio.cpp +12 -12
  93. data/src/AudioFile.hpp +5 -4
  94. data/src/AudioFileAudioToolbox.cpp +8 -8
  95. data/src/AudioFileSDLSound.cpp +7 -10
  96. data/src/BinPacker.cpp +187 -0
  97. data/src/BinPacker.hpp +55 -0
  98. data/src/Bitmap.cpp +166 -144
  99. data/src/BitmapIO.cpp +60 -86
  100. data/src/Buffer.cpp +159 -0
  101. data/src/ClipRectStack.cpp +38 -0
  102. data/src/ClipRectStack.hpp +17 -83
  103. data/src/Color.cpp +75 -80
  104. data/src/Directories.cpp +47 -0
  105. data/src/DirectoriesUIKit.cpp +50 -0
  106. data/src/DrawOp.hpp +9 -9
  107. data/src/DrawOpQueue.hpp +26 -32
  108. data/src/Drawable.cpp +95 -0
  109. data/src/EmptyDrawable.hpp +38 -0
  110. data/src/FPS.cpp +31 -0
  111. data/src/Font.cpp +104 -74
  112. data/src/GosuGLView.cpp +13 -11
  113. data/src/GosuViewController.cpp +2 -10
  114. data/src/Graphics.cpp +66 -129
  115. data/src/GraphicsImpl.hpp +14 -67
  116. data/src/Image.cpp +41 -35
  117. data/src/Input.cpp +7 -8
  118. data/src/Macro.cpp +6 -6
  119. data/src/Macro.hpp +4 -4
  120. data/src/MarkupParser.cpp +5 -5
  121. data/src/Math.cpp +35 -22
  122. data/src/OffScreenTarget.cpp +53 -49
  123. data/src/OffScreenTarget.hpp +13 -11
  124. data/src/OpenGLContext.cpp +117 -0
  125. data/src/OpenGLContext.hpp +41 -0
  126. data/src/RenderState.hpp +45 -56
  127. data/src/Resolution.cpp +23 -21
  128. data/src/TexChunk.cpp +35 -80
  129. data/src/TexChunk.hpp +44 -35
  130. data/src/Text.cpp +1 -1
  131. data/src/TextBuilder.cpp +35 -21
  132. data/src/TextBuilder.hpp +6 -9
  133. data/src/Texture.cpp +62 -80
  134. data/src/Texture.hpp +25 -23
  135. data/src/TiledDrawable.cpp +150 -0
  136. data/src/TiledDrawable.hpp +47 -0
  137. data/src/TimingApple.cpp +1 -1
  138. data/src/Transform.cpp +45 -50
  139. data/src/TransformStack.hpp +16 -16
  140. data/src/TrueTypeFont.cpp +59 -51
  141. data/src/TrueTypeFont.hpp +6 -7
  142. data/src/TrueTypeFontApple.cpp +28 -19
  143. data/src/TrueTypeFontUnix.cpp +27 -23
  144. data/src/TrueTypeFontWin.cpp +30 -30
  145. data/src/Utility.cpp +84 -21
  146. data/src/UtilityWin.cpp +45 -0
  147. data/src/Window.cpp +92 -142
  148. data/src/WindowUIKit.cpp +14 -14
  149. metadata +74 -32
  150. data/include/Gosu/IO.hpp +0 -254
  151. data/include/Gosu/ImageData.hpp +0 -53
  152. data/include/Gosu/Inspection.hpp +0 -7
  153. data/lib/gosu/patches.rb +0 -66
  154. data/lib/gosu/run.rb +0 -20
  155. data/lib/gosu/swig_patches.rb +0 -110
  156. data/src/BlockAllocator.cpp +0 -131
  157. data/src/BlockAllocator.hpp +0 -32
  158. data/src/DirectoriesApple.cpp +0 -69
  159. data/src/DirectoriesUnix.cpp +0 -46
  160. data/src/DirectoriesWin.cpp +0 -65
  161. data/src/EmptyImageData.hpp +0 -52
  162. data/src/FileUnix.cpp +0 -99
  163. data/src/FileWin.cpp +0 -88
  164. data/src/IO.cpp +0 -60
  165. data/src/Iconv.hpp +0 -51
  166. data/src/Inspection.cpp +0 -27
  167. data/src/LargeImageData.cpp +0 -215
  168. data/src/LargeImageData.hpp +0 -39
  169. data/src/Log.hpp +0 -19
  170. data/src/RubyGosu.cxx +0 -13100
  171. data/src/RubyGosu.h +0 -49
  172. data/src/WinUtility.cpp +0 -61
  173. data/src/WinUtility.hpp +0 -27
data/src/Graphics.cpp CHANGED
@@ -5,47 +5,42 @@
5
5
  #include "DrawOp.hpp"
6
6
  #include "DrawOpQueue.hpp"
7
7
  #include "GraphicsImpl.hpp"
8
- #include "LargeImageData.hpp"
9
8
  #include "Macro.hpp"
10
9
  #include "OffScreenTarget.hpp"
11
- #include "Texture.hpp"
10
+ #include "OpenGLContext.hpp"
12
11
  #include <algorithm>
13
- #include <cmath>
14
- #include <functional>
15
12
  #include <memory>
16
13
 
17
14
  namespace Gosu
18
15
  {
19
16
  namespace
20
17
  {
21
- Graphics* current_graphics_pointer = nullptr;
18
+ Viewport* current_viewport_pointer = nullptr;
22
19
 
23
- Graphics& current_graphics()
20
+ Viewport& current_viewport()
24
21
  {
25
- if (current_graphics_pointer == nullptr) {
26
- throw std::logic_error{"Gosu::Graphics can only be drawn to while rendering"};
22
+ if (current_viewport_pointer == nullptr) {
23
+ throw std::logic_error("Gosu::Graphics can only be drawn to while rendering");
27
24
  }
28
- return *current_graphics_pointer;
25
+ return *current_viewport_pointer;
29
26
  }
30
27
 
31
- std::vector<std::shared_ptr<Texture>> textures;
32
-
33
28
  DrawOpQueueStack queues;
34
29
 
35
30
  DrawOpQueue& current_queue()
36
31
  {
37
32
  if (queues.empty()) {
38
- throw std::logic_error{"There is no rendering queue for this operation"};
33
+ throw std::logic_error("There is no rendering queue for this operation");
39
34
  }
40
35
  return queues.back();
41
36
  }
42
37
  }
43
38
  }
44
39
 
45
- struct Gosu::Graphics::Impl : private Gosu::Noncopyable
40
+ struct Gosu::Viewport::Impl : private Gosu::Noncopyable
46
41
  {
47
- unsigned virt_width = 0, virt_height = 0;
48
- unsigned phys_width = 0, phys_height = 0;
42
+ int virt_width = 0, virt_height = 0;
43
+ int phys_width = 0, phys_height = 0;
49
44
  double black_width = 0.0, black_height = 0.0;
50
45
  Transform base_transform;
51
46
 
@@ -57,9 +52,9 @@ struct Gosu::Graphics::Impl : private Gosu::Noncopyable
57
52
  double scale_y = 1.0 * phys_height / virt_height;
58
53
  double scale_factor = std::min(scale_x, scale_y);
59
54
 
60
- Transform scale_transform = scale(scale_factor);
61
- Transform translate_transform = translate(black_width, black_height);
62
- base_transform = concat(translate_transform, scale_transform);
55
+ Transform scale_transform = Transform::scale(scale_factor);
56
+ Transform translate_transform = Transform::translate(black_width, black_height);
57
+ base_transform = translate_transform * scale_transform;
63
58
  }
64
59
 
65
60
  #ifndef GOSU_IS_OPENGLES
@@ -93,8 +88,8 @@ struct Gosu::Graphics::Impl : private Gosu::Noncopyable
93
88
  #endif
94
89
  };
95
90
 
96
- Gosu::Graphics::Graphics(unsigned phys_width, unsigned phys_height)
97
- : m_impl(new Impl)
91
+ Gosu::Viewport::Viewport(int phys_width, int phys_height)
92
+ : m_impl(new Impl)
98
93
  {
99
94
  m_impl->virt_width = phys_width;
100
95
  m_impl->virt_height = phys_height;
@@ -102,6 +97,7 @@ Gosu::Graphics::Graphics(unsigned phys_width, unsigned phys_height)
102
97
  m_impl->black_height = 0;
103
98
 
104
99
  // TODO: Should be merged into RenderState and removed from Graphics.
100
+ const OpenGLContext current_context;
105
101
  glMatrixMode(GL_MODELVIEW);
106
102
  glLoadIdentity();
107
103
  glEnable(GL_BLEND);
@@ -109,29 +105,29 @@ Gosu::Graphics::Graphics(unsigned phys_width, unsigned phys_height)
109
105
  set_physical_resolution(phys_width, phys_height);
110
106
  }
111
107
 
112
- Gosu::Graphics::~Graphics()
108
+ Gosu::Viewport::~Viewport()
113
109
  {
114
- if (current_graphics_pointer == this) {
115
- current_graphics_pointer = nullptr;
110
+ if (current_viewport_pointer == this) {
111
+ current_viewport_pointer = nullptr;
116
112
  }
117
113
  }
118
114
 
119
- unsigned Gosu::Graphics::width() const
115
+ int Gosu::Viewport::width() const
120
116
  {
121
117
  return m_impl->virt_width;
122
118
  }
123
119
 
124
- unsigned Gosu::Graphics::height() const
120
+ int Gosu::Viewport::height() const
125
121
  {
126
122
  return m_impl->virt_height;
127
123
  }
128
124
 
129
- void Gosu::Graphics::set_resolution(unsigned virtual_width, unsigned virtual_height,
125
+ void Gosu::Viewport::set_resolution(int virtual_width, int virtual_height,
130
126
  double horizontal_black_bar_width,
131
127
  double vertical_black_bar_height)
132
128
  {
133
- if (virtual_width == 0 || virtual_height == 0) {
134
- throw std::invalid_argument{"Invalid virtual resolution."};
129
+ if (virtual_width <= 0 || virtual_height <= 0) {
130
+ throw std::invalid_argument("Invalid virtual resolution.");
135
131
  }
136
132
 
137
133
  m_impl->virt_width = virtual_width;
@@ -142,10 +138,10 @@ void Gosu::Graphics::set_resolution(unsigned virtual_width, unsigned virtual_hei
142
138
  m_impl->update_base_transform();
143
139
  }
144
140
 
145
- void Gosu::Graphics::frame(const std::function<void()>& f)
141
+ void Gosu::Viewport::frame(const std::function<void()>& f)
146
142
  {
147
- if (current_graphics_pointer != nullptr) {
148
- throw std::logic_error{"Cannot nest calls to Gosu::Graphics::begin()"};
143
+ if (current_viewport_pointer != nullptr) {
144
+ throw std::logic_error("Cannot nest calls to Gosu::Graphics::frame()");
149
145
  }
150
146
 
151
147
  // Cancel all recording or whatever that might still be in progress...
@@ -165,16 +161,19 @@ void Gosu::Graphics::frame(const std::function<void()>& f)
165
161
 
166
162
  queues.back().set_base_transform(m_impl->base_transform);
167
163
 
168
- ensure_current_context();
164
+ const OpenGLContext current_context(true);
165
+
169
166
  glClearColor(0, 0, 0, 1);
170
167
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
171
168
 
172
- current_graphics_pointer = this;
169
+ current_viewport_pointer = this;
173
170
 
174
171
  f();
175
172
 
176
173
  // Cancel all intermediate queues that have not been cleaned up.
177
- while (queues.size() > 1) queues.pop_back();
174
+ while (queues.size() > 1) {
175
+ queues.pop_back();
176
+ }
178
177
 
179
178
  flush();
180
179
 
@@ -194,9 +193,7 @@ void Gosu::Graphics::frame(const std::function<void()>& f)
194
193
  flush();
195
194
  }
196
195
 
197
- glFlush();
198
-
199
- current_graphics_pointer = nullptr;
196
+ current_viewport_pointer = nullptr;
200
197
 
201
198
  // Clear leftover transforms, clip rects etc.
202
199
  if (queues.size() == 1) {
@@ -208,22 +205,22 @@ void Gosu::Graphics::frame(const std::function<void()>& f)
208
205
  }
209
206
  }
210
207
 
211
- void Gosu::Graphics::flush()
208
+ void Gosu::flush()
212
209
  {
213
210
  current_queue().perform_draw_ops_and_code();
214
211
  current_queue().clear_queue();
215
212
  }
216
213
 
217
- void Gosu::Graphics::gl(const std::function<void()>& f)
214
+ void Gosu::gl(const std::function<void()>& f)
218
215
  {
219
216
  if (current_queue().mode() == QM_RECORD_MACRO) {
220
- throw std::logic_error{"Custom OpenGL is not allowed while creating a macro"};
217
+ throw std::logic_error("Custom OpenGL is not allowed while creating a macro");
221
218
  }
222
219
 
223
220
  #ifdef GOSU_IS_OPENGLES
224
- throw std::logic_error{"Custom OpenGL ES is not supported yet"};
221
+ throw std::logic_error("Custom OpenGL ES is not supported yet");
225
222
  #else
226
- Graphics& cg = current_graphics();
223
+ Viewport& cg = current_viewport();
227
224
 
228
225
  flush();
229
226
 
@@ -235,13 +232,13 @@ void Gosu::Graphics::gl(const std::function<void()>& f)
235
232
  #endif
236
233
  }
237
234
 
238
- void Gosu::Graphics::gl(Gosu::ZPos z, const std::function<void()>& f)
235
+ void Gosu::gl(Gosu::ZPos z, const std::function<void()>& f)
239
236
  {
240
237
  #ifdef GOSU_IS_OPENGLES
241
- throw std::logic_error{"Custom OpenGL ES is not supported yet"};
238
+ throw std::logic_error("Custom OpenGL ES is not supported yet");
242
239
  #else
243
240
  const auto wrapped_f = [f] {
244
- Graphics& cg = current_graphics();
241
+ Viewport& cg = current_viewport();
245
242
  cg.m_impl->begin_gl();
246
243
  f();
247
244
  cg.m_impl->end_gl();
@@ -250,19 +247,22 @@ void Gosu::Graphics::gl(Gosu::ZPos z, const std::function<void()>& f)
250
247
  #endif
251
248
  }
252
249
 
253
- void Gosu::Graphics::clip_to(double x, double y, double width, double height,
254
- const std::function<void()>& f)
250
+ void Gosu::clip_to(double x, double y, double width, double height, const std::function<void()>& f)
255
251
  {
256
- double screen_height = current_graphics().m_impl->phys_height;
257
- current_queue().begin_clipping(x, y, width, height, screen_height);
252
+ std::optional<int> viewport_height;
253
+ if (current_viewport_pointer) {
254
+ viewport_height = current_viewport_pointer->m_impl->phys_height;
255
+ }
256
+
257
+ current_queue().begin_clipping(x, y, width, height, viewport_height);
258
258
  f();
259
259
  current_queue().end_clipping();
260
260
  }
261
261
 
262
- Gosu::Image Gosu::Graphics::render(int width, int height, const std::function<void()>& f,
263
- unsigned image_flags)
262
+ Gosu::Image Gosu::render(int width, int height, const std::function<void()>& f,
263
+ unsigned image_flags)
264
264
  {
265
- ensure_current_context();
265
+ const OpenGLContext current_context;
266
266
 
267
267
  // Prepare for rendering at the requested size, but save the previous matrix and viewport.
268
268
  glMatrixMode(GL_PROJECTION);
@@ -271,8 +271,8 @@ Gosu::Image Gosu::Graphics::render(int width, int height, const std::function<vo
271
271
  GLint prev_viewport[4];
272
272
  glGetIntegerv(GL_VIEWPORT, prev_viewport);
273
273
  glViewport(0, 0, width, height);
274
- // Note the flipped vertical axis in the glOrtho call - this is so we don't have to vertically
275
- // flip the texture afterwards.
274
+ // Note the flipped vertical axis in the glOrtho call, so we don't have to vertically
275
+ // flip the texture afterward.
276
276
  #ifdef GOSU_IS_OPENGLES
277
277
  glOrthof(0, width, 0, height, -1, 1); // NOLINT(readability-suspicious-call-argument)
278
278
  #else
@@ -291,7 +291,6 @@ Gosu::Image Gosu::Graphics::render(int width, int height, const std::function<vo
291
291
  f();
292
292
  queues.back().perform_draw_ops_and_code();
293
293
  queues.pop_back();
294
- glFlush();
295
294
  #ifndef GOSU_IS_OPENGLES
296
295
  glPopAttrib();
297
296
  #endif
@@ -305,25 +304,25 @@ Gosu::Image Gosu::Graphics::render(int width, int height, const std::function<vo
305
304
  return result;
306
305
  }
307
306
 
308
- Gosu::Image Gosu::Graphics::record(int width, int height, const std::function<void()>& f)
307
+ Gosu::Image Gosu::record(int width, int height, const std::function<void()>& f)
309
308
  {
310
309
  queues.emplace_back(QM_RECORD_MACRO);
311
310
 
312
311
  f();
313
312
 
314
- std::unique_ptr<ImageData> result(new Macro(current_queue(), width, height));
313
+ std::unique_ptr<Drawable> result(new Macro(current_queue(), width, height));
315
314
  queues.pop_back();
316
- return Image(move(result));
315
+ return Image(std::move(result));
317
316
  }
318
317
 
319
- void Gosu::Graphics::transform(const Gosu::Transform& transform, const std::function<void()>& f)
318
+ void Gosu::transform(const Gosu::Transform& transform, const std::function<void()>& f)
320
319
  {
321
320
  current_queue().push_transform(transform);
322
321
  f();
323
322
  current_queue().pop_transform();
324
323
  }
325
324
 
326
- void Gosu::Graphics::draw_line(double x1, double y1, Color c1, double x2, double y2, Color c2,
325
+ void Gosu::draw_line(double x1, double y1, Color c1, double x2, double y2, Color c2,
327
326
  ZPos z, BlendMode mode)
328
327
  {
329
328
  DrawOp op;
@@ -336,7 +335,7 @@ void Gosu::Graphics::draw_line(double x1, double y1, Color c1, double x2, double
336
335
  current_queue().schedule_draw_op(op);
337
336
  }
338
337
 
339
- void Gosu::Graphics::draw_triangle(double x1, double y1, Color c1, double x2, double y2, Color c2,
338
+ void Gosu::draw_triangle(double x1, double y1, Color c1, double x2, double y2, Color c2,
340
339
  double x3, double y3, Color c3, ZPos z, BlendMode mode)
341
340
  {
342
341
  DrawOp op;
@@ -354,7 +353,7 @@ void Gosu::Graphics::draw_triangle(double x1, double y1, Color c1, double x2, do
354
353
  current_queue().schedule_draw_op(op);
355
354
  }
356
355
 
357
- void Gosu::Graphics::draw_quad(double x1, double y1, Color c1, double x2, double y2, Color c2,
356
+ void Gosu::draw_quad(double x1, double y1, Color c1, double x2, double y2, Color c2,
358
357
  double x3, double y3, Color c3, double x4, double y4, Color c4,
359
358
  ZPos z, BlendMode mode)
360
359
  {
@@ -378,25 +377,26 @@ void Gosu::Graphics::draw_quad(double x1, double y1, Color c1, double x2, double
378
377
  current_queue().schedule_draw_op(op);
379
378
  }
380
379
 
381
- void Gosu::Graphics::draw_rect(double x, double y, double width, double height, Color c, ZPos z,
380
+ void Gosu::draw_rect(double x, double y, double width, double height, Color c, ZPos z,
382
381
  Gosu::BlendMode mode)
383
382
  {
384
383
  draw_quad(x, y, c, x + width, y, c, x, y + height, c, x + width, y + height, c, z, mode);
385
384
  }
386
385
 
387
- void Gosu::Graphics::schedule_draw_op(const Gosu::DrawOp& op)
386
+ void Gosu::schedule_draw_op(const Gosu::DrawOp& op)
388
387
  {
389
388
  current_queue().schedule_draw_op(op);
390
389
  }
391
390
 
392
- void Gosu::Graphics::set_physical_resolution(unsigned phys_width, unsigned phys_height)
391
+ void Gosu::Viewport::set_physical_resolution(int phys_width, int phys_height)
393
392
  {
394
393
  m_impl->phys_width = phys_width;
395
394
  m_impl->phys_height = phys_height;
396
395
  // TODO: Should be merged into RenderState and removed from Graphics.
396
+ const OpenGLContext current_context;
397
397
  glMatrixMode(GL_PROJECTION);
398
398
  glLoadIdentity();
399
- glViewport(0, 0, phys_width, phys_height);
399
+ glViewport(0, 0, static_cast<GLsizei>(phys_width), static_cast<GLsizei>(phys_height));
400
400
  #ifdef GOSU_IS_OPENGLES
401
401
  glOrthof(0, phys_width, phys_height, 0, -1, 1);
402
402
  #else
@@ -405,66 +405,3 @@ void Gosu::Graphics::set_physical_resolution(unsigned phys_width, unsigned phys_
405
405
 
406
406
  m_impl->update_base_transform();
407
407
  }
408
-
409
- std::unique_ptr<Gosu::ImageData> Gosu::Graphics::create_image(const Bitmap& src, unsigned src_x,
410
- unsigned src_y, unsigned src_width,
411
- unsigned src_height, unsigned flags)
412
- {
413
- static const unsigned max_size = MAX_TEXTURE_SIZE;
414
-
415
- // Backward compatibility: This used to be 'bool tileable'.
416
- if (flags == 1) flags = IF_TILEABLE;
417
-
418
- bool wants_retro = (flags & IF_RETRO);
419
-
420
- // Special case: If the texture is supposed to have hard borders, is
421
- // quadratic, has a size that is at least 64 pixels but no more than max_size
422
- // pixels and a power of two, create a single texture just for this image.
423
- if ((flags & IF_TILEABLE) == IF_TILEABLE && src_width == src_height &&
424
- (src_width & (src_width - 1)) == 0 && src_width >= 64 && src_width <= max_size) {
425
- std::shared_ptr<Texture> texture{new Texture(src_width, src_height, wants_retro)};
426
- std::unique_ptr<ImageData> data;
427
-
428
- // Use the source bitmap directly if the source area completely covers
429
- // it.
430
- if (src_x == 0 && src_width == src.width() && src_y == 0 && src_height == src.height()) {
431
- data = texture->try_alloc(src, 0);
432
- }
433
- else {
434
- Bitmap bmp(src_width, src_height);
435
- bmp.insert(0, 0, src, src_x, src_y, src_width, src_height);
436
- data = texture->try_alloc(bmp, 0);
437
- }
438
-
439
- if (!data) throw std::logic_error{"Internal texture block allocation error"};
440
- return data;
441
- }
442
-
443
- // Too large to fit on a single texture.
444
- if (src_width > max_size - 2 || src_height > max_size - 2) {
445
- Bitmap bmp(src_width, src_height);
446
- bmp.insert(0, 0, src, src_x, src_y, src_width, src_height);
447
- return std::unique_ptr<ImageData>{
448
- new LargeImageData(bmp, max_size - 2, max_size - 2, flags)};
449
- }
450
-
451
- Bitmap bmp = apply_border_flags(flags, src, src_x, src_y, src_width, src_height);
452
-
453
- // Try to put the bitmap into one of the already allocated textures.
454
- for (const auto& texture : textures) {
455
- if (texture->retro() != wants_retro) continue;
456
-
457
- std::unique_ptr<ImageData> data = texture->try_alloc(bmp, 1);
458
- if (data) return data;
459
- }
460
-
461
- // All textures are full: Create a new one.
462
-
463
- std::shared_ptr<Texture> texture{new Texture(max_size, max_size, wants_retro)};
464
- textures.push_back(texture);
465
-
466
- std::unique_ptr<ImageData> data{texture->try_alloc(bmp, 1)};
467
- if (!data.get()) throw std::logic_error("Internal texture block allocation error");
468
-
469
- return data;
470
- }
data/src/GraphicsImpl.hpp CHANGED
@@ -3,16 +3,8 @@
3
3
  #include <Gosu/Bitmap.hpp>
4
4
  #include <Gosu/Graphics.hpp>
5
5
  #include <Gosu/Platform.hpp>
6
-
7
- #if defined(GOSU_IS_IPHONE) || defined(GOSU_IS_OPENGLES)
8
- #include <OpenGLES/ES1/gl.h>
9
- #include <OpenGLES/ES1/glext.h>
10
- #else
11
- #include <SDL.h>
12
- #include <SDL_opengl.h>
13
- #endif
14
-
15
6
  #include <algorithm>
7
+ #include <cstdint>
16
8
  #include <list>
17
9
  #include <vector>
18
10
 
@@ -21,27 +13,6 @@ namespace Gosu
21
13
  struct RenderState;
22
14
  class RenderStateManager;
23
15
 
24
- const GLuint NO_TEXTURE = static_cast<GLuint>(-1);
25
- const unsigned NO_CLIPPING = 0xffffffff;
26
-
27
- // In various places in Gosu, width==NO_CLIPPING by convention means
28
- // that no clipping should happen.
29
- struct ClipRect
30
- {
31
- double x, y, width, height;
32
-
33
- bool operator==(const ClipRect& other) const
34
- {
35
- // No clipping
36
- return (width == NO_CLIPPING && other.width == NO_CLIPPING) ||
37
- // Clipping, but same
38
- (x == other.x && y == other.y && width == other.width && height == other.height);
39
- }
40
- };
41
- }
42
-
43
- namespace Gosu
44
- {
45
16
  enum QueueMode
46
17
  {
47
18
  QM_RENDER_TO_SCREEN,
@@ -56,59 +27,35 @@ namespace Gosu
56
27
  class DrawOpQueue;
57
28
  typedef std::list<Transform> Transforms;
58
29
  typedef std::list<DrawOpQueue> DrawOpQueueStack;
59
- class LargeImageData;
60
30
  class Macro;
61
31
  struct ArrayVertex
62
32
  {
63
- GLfloat tex_coords[2];
64
- GLuint color;
65
- GLfloat vertices[3];
33
+ float tex_coords[2];
34
+ std::uint32_t color;
35
+ float vertices[3];
66
36
  };
67
-
37
+
68
38
  template<typename T>
69
39
  bool is_p_to_the_left_of_ab(T xa, T ya, T xb, T yb, T xp, T yp)
70
40
  {
71
41
  return (xb - xa) * (yp - ya) - (xp - xa) * (yb - ya) > 0;
72
42
  }
73
-
43
+
74
44
  template<typename T, typename C>
75
45
  void normalize_coordinates(T& x1, T& y1, T& x2, T& y2, T& x3, T& y3, C& c3, T& x4, T& y4, C& c4)
76
46
  {
77
47
  if (is_p_to_the_left_of_ab(x1, y1, x2, y2, x3, y3) ==
78
48
  is_p_to_the_left_of_ab(x2, y2, x3, y3, x4, y4)) {
79
- using std::swap;
80
- swap(x3, x4);
81
- swap(y3, y4);
82
- swap(c3, c4);
49
+ std::swap(x3, x4);
50
+ std::swap(y3, y4);
51
+ std::swap(c3, c4);
83
52
  }
84
53
  }
85
-
86
- template<typename Float>
87
- void apply_transform(const Transform& transform, Float& x, Float& y)
88
- {
89
- Float in[4] = { x, y, 0, 1 };
90
- Float out[4] = { 0, 0, 0, 0 };
91
- for (int i = 0; i < 4; ++i) {
92
- for (int j = 0; j < 4; ++j) {
93
- out[i] += in[j] * transform[j * 4 + i];
94
- }
95
- }
96
- x = out[0] / out[3];
97
- y = out[1] / out[3];
98
- }
99
-
100
- #ifdef GOSU_IS_IPHONE
101
- int clip_rect_base_factor();
102
- #else
103
- inline int clip_rect_base_factor() { return 1; }
104
- #endif
105
-
106
- #ifndef GOSU_IS_IPHONE
107
- SDL_Window* shared_window();
108
- #endif
109
-
110
- void ensure_current_context();
111
-
54
+
55
+ void schedule_draw_op(const DrawOp& op);
56
+
57
+ void register_frame();
58
+
112
59
  inline std::string escape_markup(const std::string& text) {
113
60
  auto markup = text;
114
61
  for (std::string::size_type pos = 0; pos < markup.length(); ++pos) {