rays 0.1.11 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/camera.cpp +88 -0
- data/.doc/ext/rays/color.cpp +223 -45
- data/.doc/ext/rays/color_space.cpp +146 -46
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +69 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +14 -8
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +187 -292
- data/.doc/ext/rays/point.cpp +96 -77
- data/.doc/ext/rays/polygon.cpp +313 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +167 -0
- data/.doc/ext/rays/rays.cpp +103 -12
- data/.doc/ext/rays/shader.cpp +83 -9
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +24 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/camera.cpp +94 -0
- data/ext/rays/color.cpp +231 -51
- data/ext/rays/color_space.cpp +149 -47
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +2 -3
- data/ext/rays/font.cpp +74 -24
- data/ext/rays/image.cpp +28 -40
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +14 -8
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +203 -298
- data/ext/rays/point.cpp +105 -81
- data/ext/rays/polygon.cpp +329 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +176 -0
- data/ext/rays/rays.cpp +103 -13
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/camera.h +49 -0
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +15 -10
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +36 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +12 -18
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +89 -93
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +198 -0
- data/include/rays/polyline.h +71 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/camera.h +41 -0
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/rays.h +8 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +7 -2
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/camera.rb +21 -0
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +3 -7
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +78 -93
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +58 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +52 -34
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +172 -98
- data/src/image.h +25 -0
- data/src/ios/bitmap.h +21 -0
- data/src/ios/bitmap.mm +129 -110
- data/src/ios/camera.mm +236 -0
- data/src/ios/font.mm +50 -62
- data/src/ios/helper.h +2 -2
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.h +21 -0
- data/src/osx/bitmap.mm +129 -110
- data/src/osx/camera.mm +236 -0
- data/src/osx/font.mm +49 -62
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +845 -671
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1266 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +160 -0
- data/src/polyline.h +69 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_font.rb +5 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +157 -51
- data/test/test_painter_shape.rb +102 -0
- data/test/test_point.rb +29 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +171 -0
- data/test/test_shader.rb +9 -9
- metadata +102 -70
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
data/src/osx/camera.mm
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
// -*- mode: objc -*-
|
2
|
+
#import "rays/camera.h"
|
3
|
+
|
4
|
+
|
5
|
+
#import <AVFoundation/AVFoundation.h>
|
6
|
+
#include "bitmap.h"
|
7
|
+
|
8
|
+
|
9
|
+
static int video_input_queue_index = 0;
|
10
|
+
|
11
|
+
|
12
|
+
@interface VideoInput : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate>
|
13
|
+
@end
|
14
|
+
|
15
|
+
|
16
|
+
@implementation VideoInput
|
17
|
+
|
18
|
+
{
|
19
|
+
AVCaptureSession* captureSession;
|
20
|
+
dispatch_queue_t captureQueue;
|
21
|
+
CGImageRef captureImage;
|
22
|
+
}
|
23
|
+
|
24
|
+
- (id) init
|
25
|
+
{
|
26
|
+
self = [super init];
|
27
|
+
if (self)
|
28
|
+
{
|
29
|
+
captureSession = nil;
|
30
|
+
captureQueue = nil;
|
31
|
+
captureImage = nil;
|
32
|
+
}
|
33
|
+
return self;
|
34
|
+
}
|
35
|
+
|
36
|
+
- (void) dealloc
|
37
|
+
{
|
38
|
+
[self stop];
|
39
|
+
[self clearImage];
|
40
|
+
|
41
|
+
if (captureQueue)
|
42
|
+
{
|
43
|
+
dispatch_release(captureQueue);
|
44
|
+
captureQueue = nil;
|
45
|
+
}
|
46
|
+
|
47
|
+
[super dealloc];
|
48
|
+
}
|
49
|
+
|
50
|
+
- (dispatch_queue_t) queue
|
51
|
+
{
|
52
|
+
if (!captureQueue)
|
53
|
+
{
|
54
|
+
auto name = Xot::stringf(
|
55
|
+
"org.xord.RaysVideoInputQueue_%d",
|
56
|
+
video_input_queue_index++);
|
57
|
+
captureQueue = dispatch_queue_create(name, DISPATCH_QUEUE_SERIAL);
|
58
|
+
}
|
59
|
+
return captureQueue;
|
60
|
+
}
|
61
|
+
|
62
|
+
- (BOOL) start
|
63
|
+
{
|
64
|
+
[self stop];
|
65
|
+
|
66
|
+
AVCaptureSession* session = [[[AVCaptureSession alloc] init] autorelease];
|
67
|
+
session.sessionPreset = AVCaptureSessionPresetHigh;
|
68
|
+
|
69
|
+
AVCaptureDevice* device =
|
70
|
+
[AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];
|
71
|
+
if (!device) return NO;
|
72
|
+
|
73
|
+
//device.activeVideoMinFrameDuration = CMTimeMake(1, 30);
|
74
|
+
|
75
|
+
NSError* error = nil;
|
76
|
+
AVCaptureDeviceInput* input = [[[AVCaptureDeviceInput alloc]
|
77
|
+
initWithDevice: device error: &error]
|
78
|
+
autorelease];
|
79
|
+
if (!input || error || ![session canAddInput: input])
|
80
|
+
return NO;
|
81
|
+
|
82
|
+
AVCaptureVideoDataOutput* output =
|
83
|
+
[[[AVCaptureVideoDataOutput alloc] init] autorelease];
|
84
|
+
output.videoSettings = @{
|
85
|
+
(NSString*) kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)
|
86
|
+
};
|
87
|
+
output.alwaysDiscardsLateVideoFrames = YES;
|
88
|
+
[output setSampleBufferDelegate: self queue: self.queue];
|
89
|
+
if (![session canAddOutput: output])
|
90
|
+
return NO;
|
91
|
+
|
92
|
+
[session addInput: input];
|
93
|
+
[session addOutput: output];
|
94
|
+
[session startRunning];
|
95
|
+
|
96
|
+
captureSession = [session retain];
|
97
|
+
return YES;
|
98
|
+
}
|
99
|
+
|
100
|
+
- (void) captureOutput: (AVCaptureOutput*) output
|
101
|
+
didOutputSampleBuffer: (CMSampleBufferRef) sampleBuffer
|
102
|
+
fromConnection: (AVCaptureConnection*) connection
|
103
|
+
{
|
104
|
+
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
|
105
|
+
if (!pixelBuffer) return;
|
106
|
+
|
107
|
+
CIImage* ciImage = [CIImage imageWithCVPixelBuffer: pixelBuffer];
|
108
|
+
if (!ciImage) return;
|
109
|
+
|
110
|
+
CIContext* context = [CIContext contextWithOptions: nil];
|
111
|
+
size_t width = CVPixelBufferGetWidth(pixelBuffer);
|
112
|
+
size_t height = CVPixelBufferGetHeight(pixelBuffer);
|
113
|
+
CGRect rect = CGRectMake(0, 0, width, height);
|
114
|
+
CGImageRef cgImage = [context createCGImage: ciImage fromRect: rect];
|
115
|
+
|
116
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
117
|
+
[self clearImage];
|
118
|
+
captureImage = cgImage;
|
119
|
+
});
|
120
|
+
}
|
121
|
+
|
122
|
+
- (void) stop
|
123
|
+
{
|
124
|
+
if (!captureSession) return;
|
125
|
+
|
126
|
+
[captureSession stopRunning];
|
127
|
+
[captureSession release];
|
128
|
+
captureSession = nil;
|
129
|
+
}
|
130
|
+
|
131
|
+
- (BOOL) isActive
|
132
|
+
{
|
133
|
+
return captureSession != nil;
|
134
|
+
}
|
135
|
+
|
136
|
+
- (void) clearImage
|
137
|
+
{
|
138
|
+
if (!captureImage) return;
|
139
|
+
|
140
|
+
CGImageRelease(captureImage);
|
141
|
+
captureImage = nil;
|
142
|
+
}
|
143
|
+
|
144
|
+
- (CGImageRef) getImage
|
145
|
+
{
|
146
|
+
return captureImage;
|
147
|
+
}
|
148
|
+
|
149
|
+
@end// VideoInput
|
150
|
+
|
151
|
+
|
152
|
+
namespace Rays
|
153
|
+
{
|
154
|
+
|
155
|
+
|
156
|
+
struct Camera::Data
|
157
|
+
{
|
158
|
+
|
159
|
+
mutable Image image;
|
160
|
+
|
161
|
+
VideoInput* video_input = nil;
|
162
|
+
|
163
|
+
void update_image_from_video_input () const
|
164
|
+
{
|
165
|
+
if (!video_input) return;
|
166
|
+
|
167
|
+
CGImageRef cgImage = [video_input getImage];
|
168
|
+
if (!cgImage) return;
|
169
|
+
|
170
|
+
if (!image)
|
171
|
+
{
|
172
|
+
Bitmap bmp(
|
173
|
+
(int) CGImageGetWidth(cgImage),
|
174
|
+
(int) CGImageGetHeight(cgImage));
|
175
|
+
image = Image(bmp);
|
176
|
+
}
|
177
|
+
|
178
|
+
Bitmap_copy_pixels(&image.bitmap(), cgImage);
|
179
|
+
|
180
|
+
[video_input clearImage];
|
181
|
+
}
|
182
|
+
|
183
|
+
};// Camera::Data
|
184
|
+
|
185
|
+
|
186
|
+
Camera::Camera ()
|
187
|
+
{
|
188
|
+
}
|
189
|
+
|
190
|
+
Camera::~Camera ()
|
191
|
+
{
|
192
|
+
stop();
|
193
|
+
if (self->video_input) [self->video_input release];
|
194
|
+
}
|
195
|
+
|
196
|
+
bool
|
197
|
+
Camera::start ()
|
198
|
+
{
|
199
|
+
if (!self->video_input) self->video_input = [[VideoInput alloc] init];
|
200
|
+
return [self->video_input start];
|
201
|
+
}
|
202
|
+
|
203
|
+
void
|
204
|
+
Camera::stop ()
|
205
|
+
{
|
206
|
+
if (!self->video_input) return;
|
207
|
+
|
208
|
+
[self->video_input stop];
|
209
|
+
}
|
210
|
+
|
211
|
+
bool
|
212
|
+
Camera::is_active () const
|
213
|
+
{
|
214
|
+
return self->video_input && [self->video_input isActive];
|
215
|
+
}
|
216
|
+
|
217
|
+
const Image*
|
218
|
+
Camera::image () const
|
219
|
+
{
|
220
|
+
self->update_image_from_video_input();
|
221
|
+
return self->image ? &self->image : NULL;
|
222
|
+
}
|
223
|
+
|
224
|
+
Camera::operator bool () const
|
225
|
+
{
|
226
|
+
return true;
|
227
|
+
}
|
228
|
+
|
229
|
+
bool
|
230
|
+
Camera::operator ! () const
|
231
|
+
{
|
232
|
+
return !operator bool();
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
}// Rays
|
data/src/osx/font.mm
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
// -*- objc -*-
|
2
|
-
#include "
|
2
|
+
#include "../font.h"
|
3
3
|
|
4
4
|
|
5
5
|
#include <ApplicationServices/ApplicationServices.h>
|
@@ -11,7 +11,7 @@ namespace Rays
|
|
11
11
|
{
|
12
12
|
|
13
13
|
|
14
|
-
struct
|
14
|
+
struct RawFont::Data
|
15
15
|
{
|
16
16
|
|
17
17
|
CTFontRef font;
|
@@ -30,7 +30,7 @@ namespace Rays
|
|
30
30
|
}
|
31
31
|
}
|
32
32
|
|
33
|
-
};//
|
33
|
+
};// RawFont::Data
|
34
34
|
|
35
35
|
|
36
36
|
static CTLineRef
|
@@ -64,29 +64,61 @@ namespace Rays
|
|
64
64
|
}
|
65
65
|
|
66
66
|
|
67
|
-
|
67
|
+
RawFont::RawFont ()
|
68
68
|
{
|
69
69
|
}
|
70
70
|
|
71
|
-
|
71
|
+
RawFont::RawFont (const char* name, coord size)
|
72
72
|
{
|
73
73
|
self->font = name
|
74
|
-
?
|
75
|
-
:
|
74
|
+
? CTFontCreateWithName(cfstring(name).get(), size, NULL)
|
75
|
+
: CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, size, NULL);
|
76
76
|
}
|
77
77
|
|
78
|
-
|
78
|
+
RawFont::~RawFont ()
|
79
79
|
{
|
80
80
|
}
|
81
81
|
|
82
|
-
|
83
|
-
|
82
|
+
void
|
83
|
+
RawFont::draw_string (
|
84
|
+
void* context_, coord context_height,
|
85
|
+
const char* str, coord x, coord y) const
|
84
86
|
{
|
85
|
-
|
87
|
+
CGContextRef context = (CGContextRef) context_;
|
88
|
+
|
89
|
+
if (!*this || !context || !str)
|
90
|
+
argument_error(__FILE__, __LINE__);
|
91
|
+
|
92
|
+
if (*str == '\0') return;
|
93
|
+
|
94
|
+
CTLineRef line = make_line(self->font, str);
|
95
|
+
if (!line)
|
96
|
+
rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
|
97
|
+
|
98
|
+
coord width = 0, height = 0, ascent = 0;
|
99
|
+
width = get_width(str);
|
100
|
+
height = get_height(&ascent);
|
101
|
+
|
102
|
+
height = ceil(height);
|
103
|
+
ascent = floor(ascent);
|
104
|
+
|
105
|
+
CGRect rect = CGRectMake(x, context_height - height - y, width, height);
|
106
|
+
CGContextClearRect(context, rect);
|
107
|
+
//CGContextSetRGBFillColor(context, 0, 0, 0, 1);
|
108
|
+
//CGContextFillRect(context, rect);
|
109
|
+
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
|
110
|
+
|
111
|
+
CGContextSaveGState(context);
|
112
|
+
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
|
113
|
+
CGContextSetTextPosition(context, x, context_height - ascent - y);
|
114
|
+
CTLineDraw(line, context);
|
115
|
+
CGContextRestoreGState(context);
|
116
|
+
|
117
|
+
CFRelease(line);
|
86
118
|
}
|
87
119
|
|
88
120
|
String
|
89
|
-
|
121
|
+
RawFont::name () const
|
90
122
|
{
|
91
123
|
if (!*this) return "";
|
92
124
|
|
@@ -102,14 +134,14 @@ namespace Rays
|
|
102
134
|
}
|
103
135
|
|
104
136
|
coord
|
105
|
-
|
137
|
+
RawFont::size () const
|
106
138
|
{
|
107
139
|
if (!*this) return 0;
|
108
140
|
return CTFontGetSize(self->font);
|
109
141
|
}
|
110
142
|
|
111
143
|
coord
|
112
|
-
|
144
|
+
RawFont::get_width (const char* str) const
|
113
145
|
{
|
114
146
|
if (!str)
|
115
147
|
argument_error(__FILE__, __LINE__);
|
@@ -130,7 +162,7 @@ namespace Rays
|
|
130
162
|
}
|
131
163
|
|
132
164
|
coord
|
133
|
-
|
165
|
+
RawFont::get_height (coord* ascent, coord* descent, coord* leading) const
|
134
166
|
{
|
135
167
|
if (!*this)
|
136
168
|
invalid_state_error(__FILE__, __LINE__);
|
@@ -146,61 +178,16 @@ namespace Rays
|
|
146
178
|
return asc + desc + lead;
|
147
179
|
}
|
148
180
|
|
149
|
-
|
181
|
+
RawFont::operator bool () const
|
150
182
|
{
|
151
183
|
return !!self->font;
|
152
184
|
}
|
153
185
|
|
154
186
|
bool
|
155
|
-
|
187
|
+
RawFont::operator ! () const
|
156
188
|
{
|
157
189
|
return !operator bool();
|
158
190
|
}
|
159
191
|
|
160
192
|
|
161
|
-
const Font&
|
162
|
-
default_font ()
|
163
|
-
{
|
164
|
-
static const Font FONT(NULL);
|
165
|
-
return FONT;
|
166
|
-
}
|
167
|
-
|
168
|
-
|
169
|
-
void
|
170
|
-
draw_string (
|
171
|
-
CGContextRef context, coord context_height,
|
172
|
-
const char* str, coord x, coord y, const Font& font)
|
173
|
-
{
|
174
|
-
if (!context || !str || !font)
|
175
|
-
argument_error(__FILE__, __LINE__);
|
176
|
-
|
177
|
-
if (*str == '\0') return;
|
178
|
-
|
179
|
-
CTLineRef line = make_line(font.self->font, str);
|
180
|
-
if (!line)
|
181
|
-
rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
|
182
|
-
|
183
|
-
coord width = 0, height = 0, ascent = 0;
|
184
|
-
width = font.get_width(str);
|
185
|
-
height = font.get_height(&ascent);
|
186
|
-
|
187
|
-
height = ceil(height);
|
188
|
-
ascent = floor(ascent);
|
189
|
-
|
190
|
-
CGRect rect = CGRectMake(x, context_height - height - y, width, height);
|
191
|
-
CGContextClearRect(context, rect);
|
192
|
-
//CGContextSetRGBFillColor(context, 0, 0, 0, 1);
|
193
|
-
//CGContextFillRect(context, rect);
|
194
|
-
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
|
195
|
-
|
196
|
-
CGContextSaveGState(context);
|
197
|
-
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
|
198
|
-
CGContextSetTextPosition(context, x, context_height - ascent - y);
|
199
|
-
CTLineDraw(line, context);
|
200
|
-
CGContextRestoreGState(context);
|
201
|
-
|
202
|
-
CFRelease(line);
|
203
|
-
}
|
204
|
-
|
205
|
-
|
206
193
|
}// Rays
|
data/src/osx/helper.h
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#define __RAYS_SRC_OSX_HELPER_H__
|
5
5
|
|
6
6
|
|
7
|
-
#include <
|
7
|
+
#include <memory>
|
8
8
|
#include <CoreFoundation/CoreFoundation.h>
|
9
9
|
|
10
10
|
|
@@ -15,7 +15,7 @@ namespace Rays
|
|
15
15
|
void safe_cfrelease (CFTypeRef ref);
|
16
16
|
|
17
17
|
|
18
|
-
typedef
|
18
|
+
typedef std::shared_ptr<const __CFString> CFString;
|
19
19
|
|
20
20
|
CFString cfstring (const char* str);
|
21
21
|
|
data/src/osx/opengl.mm
CHANGED
@@ -1,102 +1,38 @@
|
|
1
1
|
// -*- objc -*-
|
2
|
-
#include "
|
2
|
+
#include "../opengl.h"
|
3
3
|
|
4
4
|
|
5
|
-
#
|
6
|
-
#import <Cocoa/Cocoa.h>
|
7
|
-
#import <AppKit/NSApplication.h>
|
8
|
-
#import <AppKit/NSWindow.h>
|
9
|
-
#import <AppKit/NSOpenGLView.h>
|
10
|
-
#import <OpenGL/OpenGL.h>
|
5
|
+
#import <AppKit/AppKit.h>
|
11
6
|
|
12
7
|
|
13
|
-
|
14
|
-
make_pixelformat ()
|
8
|
+
namespace Rays
|
15
9
|
{
|
16
|
-
static const NSOpenGLPixelFormatAttribute DEFAULT[] =
|
17
|
-
{
|
18
|
-
NSOpenGLPFAWindow,
|
19
|
-
//NSOpenGLPFAAccelerated,
|
20
|
-
NSOpenGLPFADoubleBuffer,
|
21
|
-
//NSOpenGLPFAColorSize, 24,
|
22
|
-
//NSOpenGLPFAAlphaSize, 8,
|
23
|
-
NSOpenGLPFADepthSize, 24,
|
24
|
-
//NSOpenGLPFANoRecovery,
|
25
|
-
};
|
26
|
-
static const size_t DEFAULT_SIZE = sizeof(DEFAULT) / sizeof(DEFAULT[0]);
|
27
|
-
|
28
|
-
std::vector<NSOpenGLPixelFormatAttribute> attr(
|
29
|
-
DEFAULT, DEFAULT + DEFAULT_SIZE);
|
30
|
-
attr.push_back(0);
|
31
|
-
|
32
|
-
return [[[NSOpenGLPixelFormat alloc] initWithAttributes: &attr[0]] autorelease];
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
@interface OffscreenGLView : NSOpenGLView
|
37
|
-
@end// OffscreenGLView
|
38
|
-
|
39
|
-
|
40
|
-
@implementation OffscreenGLView
|
41
|
-
|
42
|
-
- (id) init
|
43
|
-
{
|
44
|
-
self = [super
|
45
|
-
initWithFrame: NSMakeRect(0, 0, 0, 0)
|
46
|
-
pixelFormat: make_pixelformat()];
|
47
|
-
if (!self) return nil;
|
48
|
-
|
49
|
-
[[self openGLContext] makeCurrentContext];
|
50
|
-
return self;
|
51
|
-
}
|
52
|
-
|
53
|
-
@end// OffscreenGLView
|
54
|
-
|
55
10
|
|
56
|
-
@interface OffscreenWindow : NSWindow
|
57
11
|
|
12
|
+
void
|
13
|
+
OpenGL_set_context (Context context)
|
58
14
|
{
|
59
|
-
|
60
|
-
|
61
|
-
}
|
62
|
-
|
63
|
-
@end// OffscreenWindow
|
64
|
-
|
65
|
-
|
66
|
-
@implementation OffscreenWindow
|
67
|
-
|
68
|
-
- (id) init
|
69
|
-
{
|
70
|
-
self = [super
|
71
|
-
initWithContentRect: NSMakeRect(0, 0, 0, 0)
|
72
|
-
styleMask: 0
|
73
|
-
backing: NSBackingStoreBuffered
|
74
|
-
defer: NO];
|
75
|
-
if (!self) return nil;
|
76
|
-
|
77
|
-
view = [[OffscreenGLView alloc] init];
|
78
|
-
[self setContentView: view];
|
79
|
-
return self;
|
15
|
+
NSOpenGLContext* c = (NSOpenGLContext*) context;
|
16
|
+
[c makeCurrentContext];
|
80
17
|
}
|
81
18
|
|
82
|
-
|
19
|
+
Context
|
20
|
+
OpenGL_get_context ()
|
83
21
|
{
|
84
|
-
|
85
|
-
[super dealloc];
|
22
|
+
return [NSOpenGLContext currentContext];
|
86
23
|
}
|
87
24
|
|
88
|
-
@end// OffscreenWindow
|
89
|
-
|
90
25
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
void
|
96
|
-
init_offscreen_context ()
|
26
|
+
Context
|
27
|
+
get_offscreen_context ()
|
97
28
|
{
|
98
|
-
|
99
|
-
|
29
|
+
static Context context = NULL;
|
30
|
+
if (!context)
|
31
|
+
{
|
32
|
+
NSOpenGLPixelFormat* pf = [NSOpenGLView defaultPixelFormat];
|
33
|
+
context = [[NSOpenGLContext alloc] initWithFormat: pf shareContext: nil];
|
34
|
+
}
|
35
|
+
return context;
|
100
36
|
}
|
101
37
|
|
102
38
|
|