reflexion 0.4.1 → 0.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/.doc/ext/reflex/application.cpp +2 -0
- data/.doc/ext/reflex/device.cpp +2 -1
- data/.doc/ext/reflex/ellipse_shape.cpp +2 -0
- data/.doc/ext/reflex/filter.cpp +2 -0
- data/.doc/ext/reflex/image_view.cpp +2 -0
- data/.doc/ext/reflex/line_shape.cpp +2 -0
- data/.doc/ext/reflex/midi.cpp +2 -1
- data/.doc/ext/reflex/polygon_shape.cpp +2 -0
- data/.doc/ext/reflex/rect_shape.cpp +2 -0
- data/.doc/ext/reflex/shape.cpp +1 -0
- data/.doc/ext/reflex/timer.cpp +1 -0
- data/.doc/ext/reflex/view.cpp +1 -0
- data/.doc/ext/reflex/window.cpp +2 -0
- data/CLAUDE.md +1 -1
- data/ChangeLog.md +23 -0
- data/Rakefile +3 -2
- data/Reflex.podspec +105 -0
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +2 -0
- data/ext/reflex/device.cpp +2 -1
- data/ext/reflex/ellipse_shape.cpp +2 -0
- data/ext/reflex/filter.cpp +2 -0
- data/ext/reflex/image_view.cpp +2 -0
- data/ext/reflex/line_shape.cpp +2 -0
- data/ext/reflex/midi.cpp +2 -1
- data/ext/reflex/polygon_shape.cpp +2 -0
- data/ext/reflex/rect_shape.cpp +2 -0
- data/ext/reflex/shape.cpp +1 -0
- data/ext/reflex/timer.cpp +1 -0
- data/ext/reflex/view.cpp +1 -0
- data/ext/reflex/window.cpp +2 -0
- data/pod.rake +41 -0
- data/reflex.gemspec +3 -3
- data/samples/multi_window.rb +80 -0
- data/src/body.cpp +93 -90
- data/src/body.h +7 -7
- data/src/fixture.cpp +301 -49
- data/src/fixture.h +55 -10
- data/src/osx/app_delegate.mm +6 -4
- data/src/osx/native_window.mm +2 -2
- data/src/osx/opengl_view.mm +27 -50
- data/src/sdl/opengl.cpp +16 -14
- data/src/sdl/opengl.h +2 -2
- data/src/sdl/window.cpp +34 -5
- data/src/shape.cpp +58 -51
- data/src/shape.h +0 -3
- data/src/timer.cpp +8 -10
- data/src/view.cpp +4 -5
- data/src/win32/opengl.cpp +17 -40
- data/src/win32/opengl.h +0 -2
- data/src/win32/window.cpp +32 -15
- data/src/window.cpp +0 -1
- data/src/world.cpp +301 -128
- data/src/world.h +12 -21
- data/test/test_midi_event.rb +2 -2
- metadata +11 -8
data/src/sdl/opengl.cpp
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#include "opengl.h"
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
#include <rays/rays.h>
|
|
4
5
|
#include "reflex/exception.h"
|
|
5
6
|
|
|
6
7
|
|
|
@@ -27,9 +28,14 @@ namespace Reflex
|
|
|
27
28
|
invalid_state_error(__FILE__, __LINE__);
|
|
28
29
|
|
|
29
30
|
window = win;
|
|
30
|
-
context =
|
|
31
|
-
if (!context)
|
|
32
|
-
|
|
31
|
+
context = (SDL_GLContext) Rays::get_offscreen_context();
|
|
32
|
+
if (!context)// wasm build returns NULL
|
|
33
|
+
{
|
|
34
|
+
context = SDL_GL_CreateContext(win);
|
|
35
|
+
if (!context)
|
|
36
|
+
reflex_error(__FILE__, __LINE__, SDL_GetError());
|
|
37
|
+
owner = true;
|
|
38
|
+
}
|
|
33
39
|
|
|
34
40
|
make_current();
|
|
35
41
|
}
|
|
@@ -37,15 +43,17 @@ namespace Reflex
|
|
|
37
43
|
void
|
|
38
44
|
OpenGLContext::fin ()
|
|
39
45
|
{
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
if (context)
|
|
46
|
+
if (owner && context)
|
|
43
47
|
{
|
|
48
|
+
if (context == SDL_GL_GetCurrentContext())
|
|
49
|
+
SDL_GL_MakeCurrent(NULL, NULL);
|
|
50
|
+
|
|
44
51
|
SDL_GL_DeleteContext(context);
|
|
45
|
-
context = NULL;
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
window
|
|
54
|
+
window = NULL;
|
|
55
|
+
context = NULL;
|
|
56
|
+
owner = false;
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
void
|
|
@@ -65,12 +73,6 @@ namespace Reflex
|
|
|
65
73
|
SDL_GL_SwapWindow(window);
|
|
66
74
|
}
|
|
67
75
|
|
|
68
|
-
bool
|
|
69
|
-
OpenGLContext::is_active () const
|
|
70
|
-
{
|
|
71
|
-
return *this && context == SDL_GL_GetCurrentContext();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
76
|
OpenGLContext::operator bool () const
|
|
75
77
|
{
|
|
76
78
|
return window && context;
|
data/src/sdl/opengl.h
CHANGED
|
@@ -28,8 +28,6 @@ namespace Reflex
|
|
|
28
28
|
|
|
29
29
|
void swap_buffers ();
|
|
30
30
|
|
|
31
|
-
bool is_active () const;
|
|
32
|
-
|
|
33
31
|
operator bool () const;
|
|
34
32
|
|
|
35
33
|
bool operator ! () const;
|
|
@@ -40,6 +38,8 @@ namespace Reflex
|
|
|
40
38
|
|
|
41
39
|
SDL_GLContext context = NULL;
|
|
42
40
|
|
|
41
|
+
bool owner = false;
|
|
42
|
+
|
|
43
43
|
};// OpenGLContext
|
|
44
44
|
|
|
45
45
|
|
data/src/sdl/window.cpp
CHANGED
|
@@ -22,6 +22,8 @@ namespace Reflex
|
|
|
22
22
|
|
|
23
23
|
SDL_Window* native = NULL;
|
|
24
24
|
|
|
25
|
+
bool need_rebind = false;
|
|
26
|
+
|
|
25
27
|
OpenGLContext context;
|
|
26
28
|
|
|
27
29
|
mutable String title_tmp;
|
|
@@ -47,6 +49,21 @@ namespace Reflex
|
|
|
47
49
|
|
|
48
50
|
context.init(native);
|
|
49
51
|
|
|
52
|
+
// Reflex::Window is not fully constructed yet,
|
|
53
|
+
// so cannot call ClassWrapper::retain().
|
|
54
|
+
win->Xot::template RefCountable<>::retain();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
void rebind (Window* win)
|
|
58
|
+
{
|
|
59
|
+
if (!need_rebind) return;
|
|
60
|
+
|
|
61
|
+
// deferred call of ClassWrapper::retain().
|
|
62
|
+
win->retain();
|
|
63
|
+
|
|
64
|
+
win->Xot::template RefCountable<>::release();
|
|
65
|
+
need_rebind = false;
|
|
66
|
+
|
|
50
67
|
Window_register(win);
|
|
51
68
|
}
|
|
52
69
|
|
|
@@ -54,15 +71,21 @@ namespace Reflex
|
|
|
54
71
|
{
|
|
55
72
|
if (!native) return;
|
|
56
73
|
|
|
57
|
-
context.fin();
|
|
58
|
-
|
|
59
74
|
Window* win = Window_from(native);
|
|
60
|
-
if (win)
|
|
75
|
+
if (win)
|
|
76
|
+
{
|
|
77
|
+
rebind(win);
|
|
78
|
+
Window_unregister(win);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
context.fin();
|
|
61
82
|
|
|
62
83
|
SDL_SetWindowData(native, WINDOW_DATA_KEY, NULL);
|
|
63
84
|
SDL_DestroyWindow(native);
|
|
64
85
|
native = NULL;
|
|
65
86
|
|
|
87
|
+
if (win) win->release();
|
|
88
|
+
|
|
66
89
|
if (Window_all().empty())
|
|
67
90
|
Reflex::app()->quit();
|
|
68
91
|
}
|
|
@@ -181,7 +204,11 @@ namespace Reflex
|
|
|
181
204
|
void
|
|
182
205
|
Window_initialize (Window* win)
|
|
183
206
|
{
|
|
184
|
-
get_data(win)
|
|
207
|
+
WindowData* self = get_data(win);
|
|
208
|
+
|
|
209
|
+
self->create(win);
|
|
210
|
+
|
|
211
|
+
self->need_rebind = true;
|
|
185
212
|
}
|
|
186
213
|
|
|
187
214
|
void
|
|
@@ -322,6 +349,8 @@ namespace Reflex
|
|
|
322
349
|
{
|
|
323
350
|
WindowData* self = get_data(win);
|
|
324
351
|
|
|
352
|
+
self->rebind(win);
|
|
353
|
+
|
|
325
354
|
switch (event.type)
|
|
326
355
|
{
|
|
327
356
|
case SDL_WINDOWEVENT:
|
|
@@ -329,7 +358,7 @@ namespace Reflex
|
|
|
329
358
|
switch (event.window.event)
|
|
330
359
|
{
|
|
331
360
|
case SDL_WINDOWEVENT_CLOSE:
|
|
332
|
-
|
|
361
|
+
win->close();
|
|
333
362
|
break;
|
|
334
363
|
|
|
335
364
|
case SDL_WINDOWEVENT_EXPOSED:
|
data/src/shape.cpp
CHANGED
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
#include <assert.h>
|
|
5
|
-
#include <box2d/
|
|
6
|
-
#include <box2d/
|
|
7
|
-
#include <box2d/b2_circle_shape.h>
|
|
8
|
-
#include <box2d/b2_edge_shape.h>
|
|
9
|
-
#include <box2d/b2_chain_shape.h>
|
|
10
|
-
#include <box2d/b2_polygon_shape.h>
|
|
5
|
+
#include <box2d/box2d.h>
|
|
6
|
+
#include <box2d/collision.h>
|
|
11
7
|
#include <rays/polygon.h>
|
|
12
8
|
#include "reflex/exception.h"
|
|
13
9
|
#include "reflex/debug.h"
|
|
@@ -105,23 +101,25 @@ namespace Reflex
|
|
|
105
101
|
|
|
106
102
|
public:
|
|
107
103
|
|
|
108
|
-
FixtureBuilder (Shape* shape
|
|
104
|
+
FixtureBuilder (Shape* shape)
|
|
109
105
|
: shape(shape), head(NULL), tail(NULL)
|
|
110
106
|
{
|
|
111
107
|
assert(shape);
|
|
112
|
-
|
|
113
|
-
if (head) add(head);
|
|
114
108
|
}
|
|
115
109
|
|
|
116
|
-
void add (const
|
|
110
|
+
void add (const b2Circle& b2circle)
|
|
117
111
|
{
|
|
118
|
-
|
|
112
|
+
append(new Fixture(get_body(), b2circle, shape));
|
|
113
|
+
}
|
|
119
114
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
void add (const b2Polygon& b2polygon)
|
|
116
|
+
{
|
|
117
|
+
append(new Fixture(get_body(), b2polygon, shape));
|
|
118
|
+
}
|
|
123
119
|
|
|
124
|
-
|
|
120
|
+
void add (const b2Vec2* points, size_t size, bool loop)
|
|
121
|
+
{
|
|
122
|
+
append(new Fixture(get_body(), points, size, loop, shape));
|
|
125
123
|
}
|
|
126
124
|
|
|
127
125
|
Fixture* fixtures () const
|
|
@@ -135,6 +133,15 @@ namespace Reflex
|
|
|
135
133
|
|
|
136
134
|
Fixture *head, *tail;
|
|
137
135
|
|
|
136
|
+
Body* get_body ()
|
|
137
|
+
{
|
|
138
|
+
Body* body = View_get_body(shape->owner());
|
|
139
|
+
if (!body)
|
|
140
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
141
|
+
|
|
142
|
+
return body;
|
|
143
|
+
}
|
|
144
|
+
|
|
138
145
|
void append (Fixture* fixture)
|
|
139
146
|
{
|
|
140
147
|
if (!fixture) return;
|
|
@@ -159,8 +166,11 @@ namespace Reflex
|
|
|
159
166
|
{
|
|
160
167
|
assert(shape);
|
|
161
168
|
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
b2Circle b2shape = {{0, 0}, 0};
|
|
170
|
+
|
|
171
|
+
FixtureBuilder builder(shape);
|
|
172
|
+
builder.add(b2shape);
|
|
173
|
+
return builder.fixtures();
|
|
164
174
|
}
|
|
165
175
|
|
|
166
176
|
static Fixture*
|
|
@@ -185,12 +195,11 @@ namespace Reflex
|
|
|
185
195
|
FixtureBuilder builder(shape);
|
|
186
196
|
for (size_t i = 0; i < b2points.size(); i += 3)
|
|
187
197
|
{
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (b2shape.m_count != 3)
|
|
198
|
+
b2Hull hull = b2ComputeHull(&b2points[i], 3);
|
|
199
|
+
if (hull.count != 3)
|
|
191
200
|
continue;// skip too small triangle
|
|
192
201
|
|
|
193
|
-
builder.add(&
|
|
202
|
+
builder.add(b2MakePolygon(&hull, 0));
|
|
194
203
|
}
|
|
195
204
|
|
|
196
205
|
return builder.fixtures();
|
|
@@ -203,24 +212,15 @@ namespace Reflex
|
|
|
203
212
|
{
|
|
204
213
|
assert(builder && buffer);
|
|
205
214
|
|
|
215
|
+
if (polyline.size() < 2)
|
|
216
|
+
return;
|
|
217
|
+
|
|
206
218
|
buffer->clear();
|
|
207
219
|
buffer->reserve(polyline.size());
|
|
208
220
|
for (const auto& point : polyline)
|
|
209
221
|
buffer->emplace_back(to_b2vec2(point, ppm));
|
|
210
222
|
|
|
211
|
-
|
|
212
|
-
if (polyline.loop())
|
|
213
|
-
b2shape.CreateLoop(&(*buffer)[0], (int32) buffer->size());
|
|
214
|
-
else
|
|
215
|
-
{
|
|
216
|
-
b2shape.CreateChain(
|
|
217
|
-
&(*buffer)[0],
|
|
218
|
-
(int32) buffer->size(),
|
|
219
|
-
(*buffer)[0],
|
|
220
|
-
(*buffer)[buffer->size() - 1]);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
builder->add(&b2shape);
|
|
223
|
+
builder->add(buffer->data(), buffer->size(), polyline.loop());
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
static Fixture*
|
|
@@ -816,20 +816,22 @@ namespace Reflex
|
|
|
816
816
|
invalid_state_error(__FILE__, __LINE__);
|
|
817
817
|
|
|
818
818
|
float ppm = owner->meter2pixel();
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
819
|
+
float l = to_b2coord(frame.x, ppm);
|
|
820
|
+
float t = to_b2coord(frame.y, ppm);
|
|
821
|
+
float r = to_b2coord(frame.x + frame.w, ppm);
|
|
822
|
+
float b = to_b2coord(frame.y + frame.h, ppm);
|
|
823
823
|
b2Vec2 b2points[] = {{l, t}, {l, b}, {r, b}, {r, t}};
|
|
824
824
|
|
|
825
|
-
|
|
826
|
-
|
|
825
|
+
b2Hull hull = b2ComputeHull(&b2points[0], 4);
|
|
826
|
+
if (hull.count < 3)
|
|
827
|
+
return NULL;
|
|
827
828
|
|
|
828
|
-
|
|
829
|
+
FixtureBuilder builder(shape);
|
|
830
|
+
builder.add(b2MakePolygon(&hull, 0));
|
|
831
|
+
return builder.fixtures();
|
|
829
832
|
}
|
|
830
833
|
|
|
831
|
-
Fixture* create_rect_fixture_without_division (
|
|
832
|
-
Shape* shape, const Bounds& frame)
|
|
834
|
+
Fixture* create_rect_fixture_without_division (Shape* shape, const Bounds& frame)
|
|
833
835
|
{
|
|
834
836
|
assert(shape);
|
|
835
837
|
|
|
@@ -845,16 +847,19 @@ namespace Reflex
|
|
|
845
847
|
|
|
846
848
|
float ppm = owner->meter2pixel();
|
|
847
849
|
const Polyline& polyline = polygon[0];
|
|
848
|
-
assert(polyline
|
|
850
|
+
assert(polyline.size() <= 8);
|
|
849
851
|
|
|
850
852
|
b2Vec2 b2points[8];
|
|
851
853
|
for (size_t i = 0; i < polyline.size(); ++i)
|
|
852
854
|
b2points[i] = to_b2vec2(polyline[i], ppm);
|
|
853
855
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
+
b2Hull hull = b2ComputeHull(&b2points[0], (int32_t) polyline.size());
|
|
857
|
+
if (hull.count < 3)
|
|
858
|
+
return NULL;
|
|
856
859
|
|
|
857
|
-
|
|
860
|
+
FixtureBuilder builder(shape);
|
|
861
|
+
builder.add(b2MakePolygon(&hull, 0));
|
|
862
|
+
return builder.fixtures();
|
|
858
863
|
}
|
|
859
864
|
|
|
860
865
|
Polygon get_polygon_for_shape () const override
|
|
@@ -1049,11 +1054,13 @@ namespace Reflex
|
|
|
1049
1054
|
|
|
1050
1055
|
float ppm = owner->meter2pixel();
|
|
1051
1056
|
|
|
1052
|
-
|
|
1053
|
-
b2shape.
|
|
1054
|
-
b2shape.
|
|
1057
|
+
b2Circle b2shape;
|
|
1058
|
+
b2shape.center = to_b2vec2(frame.center(), ppm);
|
|
1059
|
+
b2shape.radius = to_b2coord(frame.width / 2, ppm);
|
|
1055
1060
|
|
|
1056
|
-
|
|
1061
|
+
FixtureBuilder builder(shape);
|
|
1062
|
+
builder.add(b2shape);
|
|
1063
|
+
return builder.fixtures();
|
|
1057
1064
|
}
|
|
1058
1065
|
|
|
1059
1066
|
Polygon get_polygon_for_shape () const override
|
data/src/shape.h
CHANGED
data/src/timer.cpp
CHANGED
|
@@ -16,20 +16,17 @@ namespace Reflex
|
|
|
16
16
|
struct Timer::Data
|
|
17
17
|
{
|
|
18
18
|
|
|
19
|
-
View
|
|
19
|
+
Xot::WeakRef<View> owner;
|
|
20
20
|
|
|
21
|
-
int id
|
|
21
|
+
int id = ID_INVALID;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
int count = 1;
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
float interval = -1;
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
double next_time = -1;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
: owner(NULL), id(ID_INVALID), count(1), interval(-1), next_time(-1)
|
|
31
|
-
{
|
|
32
|
-
}
|
|
29
|
+
SelectorPtr pselector;
|
|
33
30
|
|
|
34
31
|
Selector& selector ()
|
|
35
32
|
{
|
|
@@ -66,6 +63,7 @@ namespace Reflex
|
|
|
66
63
|
void
|
|
67
64
|
Timer::fire ()
|
|
68
65
|
{
|
|
66
|
+
if (!self->owner) return;
|
|
69
67
|
if (!*this)
|
|
70
68
|
invalid_state_error(__FILE__, __LINE__);
|
|
71
69
|
|
|
@@ -82,7 +80,7 @@ namespace Reflex
|
|
|
82
80
|
View*
|
|
83
81
|
Timer::owner () const
|
|
84
82
|
{
|
|
85
|
-
return self->owner;
|
|
83
|
+
return self->owner.get();
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
int
|
data/src/view.cpp
CHANGED
|
@@ -318,6 +318,7 @@ namespace Reflex
|
|
|
318
318
|
clear_walls(view);
|
|
319
319
|
|
|
320
320
|
View* wall = new View(WALL_NAME);
|
|
321
|
+
wall->set_shape(NULL);
|
|
321
322
|
wall->add_shape(new WallShape(WallShape::ALL));
|
|
322
323
|
wall->set_static();
|
|
323
324
|
|
|
@@ -1890,11 +1891,9 @@ namespace Reflex
|
|
|
1890
1891
|
void
|
|
1891
1892
|
View::clear_children ()
|
|
1892
1893
|
{
|
|
1893
|
-
auto
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
for (auto& child : *children)
|
|
1897
|
-
remove_child(child);
|
|
1894
|
+
const auto& children = self->pchildren;
|
|
1895
|
+
while (children && !children->empty())
|
|
1896
|
+
remove_child(children->back());
|
|
1898
1897
|
}
|
|
1899
1898
|
|
|
1900
1899
|
View::ChildList
|
data/src/win32/opengl.cpp
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
#include "opengl.h"
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
#include <rays/rays.h>
|
|
4
5
|
#include "reflex/exception.h"
|
|
5
6
|
|
|
6
7
|
|
|
8
|
+
namespace Rays
|
|
9
|
+
{
|
|
10
|
+
|
|
11
|
+
const PIXELFORMATDESCRIPTOR* get_pixel_format_descriptor ();
|
|
12
|
+
|
|
13
|
+
}// Rays
|
|
14
|
+
|
|
15
|
+
|
|
7
16
|
namespace Reflex
|
|
8
17
|
{
|
|
9
18
|
|
|
@@ -31,22 +40,15 @@ namespace Reflex
|
|
|
31
40
|
if (!hdc)
|
|
32
41
|
system_error(__FILE__, __LINE__);
|
|
33
42
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
sizeof(PIXELFORMATDESCRIPTOR), 1,
|
|
37
|
-
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
|
|
38
|
-
PFD_TYPE_RGBA, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0,
|
|
39
|
-
PFD_MAIN_PLANE, 0, 0, 0, 0
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
int pf = ChoosePixelFormat(hdc, &PFD);
|
|
43
|
+
const auto* pfd = Rays::get_pixel_format_descriptor();
|
|
44
|
+
int pf = ChoosePixelFormat(hdc, pfd);
|
|
43
45
|
if (pf == 0)
|
|
44
46
|
system_error(__FILE__, __LINE__);
|
|
45
47
|
|
|
46
|
-
if (!SetPixelFormat(hdc, pf,
|
|
48
|
+
if (!SetPixelFormat(hdc, pf, pfd))
|
|
47
49
|
system_error(__FILE__, __LINE__);
|
|
48
50
|
|
|
49
|
-
hrc =
|
|
51
|
+
hrc = (HGLRC) Rays::get_offscreen_context();
|
|
50
52
|
if (!hrc)
|
|
51
53
|
system_error(__FILE__, __LINE__);
|
|
52
54
|
|
|
@@ -56,31 +58,12 @@ namespace Reflex
|
|
|
56
58
|
void
|
|
57
59
|
OpenGLContext::fin ()
|
|
58
60
|
{
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
if (hrc)
|
|
62
|
-
{
|
|
63
|
-
if (hrc == wglGetCurrentContext())
|
|
64
|
-
{
|
|
65
|
-
if (!wglMakeCurrent(NULL, NULL))
|
|
66
|
-
system_error(__FILE__, __LINE__);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!wglDeleteContext(hrc))
|
|
70
|
-
system_error(__FILE__, __LINE__);
|
|
71
|
-
|
|
72
|
-
hrc = NULL;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (hdc)
|
|
76
|
-
{
|
|
77
|
-
if (!ReleaseDC(hwnd, hdc))
|
|
78
|
-
system_error(__FILE__, __LINE__);
|
|
79
|
-
|
|
80
|
-
hdc = NULL;
|
|
81
|
-
}
|
|
61
|
+
if (hdc && !ReleaseDC(hwnd, hdc))
|
|
62
|
+
system_error(__FILE__, __LINE__);
|
|
82
63
|
|
|
83
64
|
hwnd = NULL;
|
|
65
|
+
hdc = NULL;
|
|
66
|
+
hrc = NULL;
|
|
84
67
|
}
|
|
85
68
|
|
|
86
69
|
void
|
|
@@ -101,12 +84,6 @@ namespace Reflex
|
|
|
101
84
|
system_error(__FILE__, __LINE__);
|
|
102
85
|
}
|
|
103
86
|
|
|
104
|
-
bool
|
|
105
|
-
OpenGLContext::is_active () const
|
|
106
|
-
{
|
|
107
|
-
return *this && hrc == wglGetCurrentContext();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
87
|
OpenGLContext::operator bool () const
|
|
111
88
|
{
|
|
112
89
|
return hwnd && hdc && hrc;
|
data/src/win32/opengl.h
CHANGED
data/src/win32/window.cpp
CHANGED
|
@@ -32,7 +32,9 @@ namespace Reflex
|
|
|
32
32
|
struct WindowData : public Window::Data
|
|
33
33
|
{
|
|
34
34
|
|
|
35
|
-
HWND hwnd
|
|
35
|
+
HWND hwnd = NULL;
|
|
36
|
+
|
|
37
|
+
bool need_rebind = false;
|
|
36
38
|
|
|
37
39
|
OpenGLContext context;
|
|
38
40
|
|
|
@@ -118,7 +120,25 @@ namespace Reflex
|
|
|
118
120
|
|
|
119
121
|
self->hwnd = hwnd;
|
|
120
122
|
self->context.init(hwnd);
|
|
123
|
+
|
|
124
|
+
// Reflex::Window is not fully constructed yet,
|
|
125
|
+
// so cannot call ClassWrapper::retain().
|
|
126
|
+
win->Xot::template RefCountable<>::retain();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static inline void
|
|
130
|
+
rebind (Window* win)
|
|
131
|
+
{
|
|
132
|
+
WindowData* self = get_data(win);
|
|
133
|
+
if (!self->need_rebind) return;
|
|
134
|
+
|
|
135
|
+
// deferred call of ClassWrapper::retain().
|
|
121
136
|
win->retain();
|
|
137
|
+
|
|
138
|
+
win->Xot::template RefCountable<>::release();
|
|
139
|
+
self->need_rebind = false;
|
|
140
|
+
|
|
141
|
+
Window_register(win);
|
|
122
142
|
}
|
|
123
143
|
|
|
124
144
|
static void
|
|
@@ -127,6 +147,9 @@ namespace Reflex
|
|
|
127
147
|
if (!*win)
|
|
128
148
|
Xot::invalid_state_error(__FILE__, __LINE__);
|
|
129
149
|
|
|
150
|
+
rebind(win);
|
|
151
|
+
Window_unregister(win);
|
|
152
|
+
|
|
130
153
|
WindowData* self = get_data(win);
|
|
131
154
|
|
|
132
155
|
if (window_has_wndproc(self->hwnd))
|
|
@@ -142,12 +165,13 @@ namespace Reflex
|
|
|
142
165
|
system_error(__FILE__, __LINE__);
|
|
143
166
|
}
|
|
144
167
|
|
|
145
|
-
if (self->context.is_active())
|
|
146
|
-
Rays::activate_offscreen_context();
|
|
147
|
-
|
|
148
168
|
self->context.fin();
|
|
149
169
|
self->hwnd = NULL;
|
|
170
|
+
|
|
150
171
|
win->release();
|
|
172
|
+
|
|
173
|
+
if (Window_all().empty())
|
|
174
|
+
Reflex::app()->quit();
|
|
151
175
|
}
|
|
152
176
|
|
|
153
177
|
void
|
|
@@ -456,25 +480,16 @@ namespace Reflex
|
|
|
456
480
|
CREATESTRUCT* cs = (CREATESTRUCT*) lp;
|
|
457
481
|
win = (Window*) cs->lpCreateParams;
|
|
458
482
|
setup_window(win, hwnd);
|
|
459
|
-
|
|
460
|
-
Window_register(win);
|
|
461
483
|
}
|
|
462
484
|
|
|
463
|
-
if (!win)
|
|
464
|
-
|
|
485
|
+
if (!win) win = get_window_from_hwnd(hwnd);
|
|
486
|
+
if (win) rebind(win);
|
|
465
487
|
|
|
466
488
|
LRESULT ret = window_proc(win, hwnd, msg, wp, lp);
|
|
467
489
|
|
|
468
490
|
if (msg == WM_NCDESTROY)
|
|
469
|
-
{
|
|
470
|
-
Window_unregister(win);
|
|
471
|
-
|
|
472
491
|
cleanup_window(win);
|
|
473
492
|
|
|
474
|
-
if (Window_all().empty())
|
|
475
|
-
Reflex::app()->quit();
|
|
476
|
-
}
|
|
477
|
-
|
|
478
493
|
return ret;
|
|
479
494
|
}
|
|
480
495
|
|
|
@@ -546,6 +561,8 @@ namespace Reflex
|
|
|
546
561
|
Window_initialize (Window* window)
|
|
547
562
|
{
|
|
548
563
|
create_window(window);
|
|
564
|
+
|
|
565
|
+
get_data(window)->need_rebind = true;
|
|
549
566
|
}
|
|
550
567
|
|
|
551
568
|
void
|