aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/modules/engines/gl_cocoa/evas_gl_cocoa_main.m
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/evas/src/modules/engines/gl_cocoa/evas_gl_cocoa_main.m')
-rw-r--r--libraries/evas/src/modules/engines/gl_cocoa/evas_gl_cocoa_main.m134
1 files changed, 134 insertions, 0 deletions
diff --git a/libraries/evas/src/modules/engines/gl_cocoa/evas_gl_cocoa_main.m b/libraries/evas/src/modules/engines/gl_cocoa/evas_gl_cocoa_main.m
new file mode 100644
index 0000000..aa6b895
--- /dev/null
+++ b/libraries/evas/src/modules/engines/gl_cocoa/evas_gl_cocoa_main.m
@@ -0,0 +1,134 @@
1
2#include <Cocoa/Cocoa.h>
3
4#include "evas_engine.h"
5
6static Evas_GL_Cocoa_Window *_evas_gl_cocoa_window = NULL;
7
8@interface EvasGLView : NSOpenGLView
9{
10}
11
12+ (NSOpenGLPixelFormat*) basicPixelFormat;
13- (id) initWithFrame: (NSRect) frameRect;
14
15@end
16
17
18@implementation EvasGLView
19
20- (id) init
21{
22 self = [super init];
23 return self;
24}
25
26+ (NSOpenGLPixelFormat*) basicPixelFormat
27{
28 NSOpenGLPixelFormatAttribute attributes [] = {
29 NSOpenGLPFAWindow,
30 NSOpenGLPFAAccelerated,
31 NSOpenGLPFADoubleBuffer,
32 /*NSOpenGLPFAColorSize, 24,
33 NSOpenGLPFAAlphaSize, 8,
34 NSOpenGLPFADepthSize, 24,*/
35 0
36 };
37 return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
38}
39
40// ---------------------------------
41
42-(id) initWithFrame: (NSRect) frameRect
43{
44 NSOpenGLPixelFormat * pf = [EvasGLView basicPixelFormat];
45 self = [super initWithFrame: frameRect pixelFormat: pf];
46 return self;
47}
48
49@end
50
51
52Evas_GL_Cocoa_Window *
53eng_window_new(void *window,
54 int w,
55 int h)
56{
57 Evas_GL_Cocoa_Window *gw;
58 int context_attrs[3];
59 int config_attrs[20];
60 int major_version, minor_version;
61 int num_config;
62
63 gw = calloc(1, sizeof(Evas_GL_Cocoa_Window));
64 if (!gw) return NULL;
65
66 _evas_gl_cocoa_window = gw;
67 gw->window = window;
68 gw->view = [[EvasGLView alloc] initWithFrame:NSMakeRect(0,0,w,h)];
69 NSOpenGLContext *ctx = [(NSOpenGLView*)gw->view openGLContext];
70 [ctx makeCurrentContext];
71 gw->gl_context = evas_gl_common_context_new();
72
73 if (!gw->gl_context)
74 {
75 free(gw);
76 return NULL;
77 }
78 evas_gl_common_context_use(gw->gl_context);
79 evas_gl_common_context_resize(gw->gl_context, w, h, 0);
80
81 return gw;
82}
83
84void
85eng_window_free(Evas_GL_Cocoa_Window *gw)
86{
87 if (gw == _evas_gl_cocoa_window) _evas_gl_cocoa_window = NULL;
88 evas_gl_common_context_free(gw->gl_context);
89 free(gw);
90}
91
92void
93eng_window_use(Evas_GL_Cocoa_Window *gw)
94{
95 if (_evas_gl_cocoa_window != gw)
96 {
97 [[(NSOpenGLView*)gw->view openGLContext] makeCurrentContext];
98 if (_evas_gl_cocoa_window)
99 evas_gl_common_context_flush(_evas_gl_cocoa_window->gl_context);
100 _evas_gl_cocoa_window = gw;
101
102 }
103 evas_gl_common_context_use(gw->gl_context);
104}
105
106void
107eng_window_swap_buffers(Evas_GL_Cocoa_Window *gw)
108{
109 [[(NSOpenGLView*)gw->view openGLContext] flushBuffer];
110}
111
112void
113eng_window_vsync_set(int on)
114{
115
116}
117
118
119void
120eng_window_resize(Evas_GL_Cocoa_Window *gw, int width, int height)
121{
122 NSRect view_frame;
123
124 INF("Resize %d %d\n", width, height);
125
126 view_frame = [(EvasGLView*)gw->view frame];
127 printf("view_frame : %3.3f %3.3f\n", view_frame.size.height, view_frame.size.width);
128 view_frame.size.height = height;
129 view_frame.size.width = width;
130 printf("view_frame : %3.3f %3.3f\n", view_frame.size.height, view_frame.size.width);
131 [(EvasGLView*)gw->view setFrame:view_frame];
132 [[(NSOpenGLView*)gw->view openGLContext] flushBuffer];
133}
134