Mercurial > projects > dwt-mac
comparison dwt/opengl/GLCanvas.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | e831403a80a9 |
children | 580596d83ac4 |
comparison
equal
deleted
inserted
replaced
44:ca5e494f2bbf | 45:d8635bb48c7c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
24 import dwt.widgets.Listener; | 24 import dwt.widgets.Listener; |
25 | 25 |
26 /** | 26 /** |
27 * GLCanvas is a widget capable of displaying OpenGL content. | 27 * GLCanvas is a widget capable of displaying OpenGL content. |
28 * | 28 * |
29 * @see GLData | |
30 * @see <a href="http://www.eclipse.org/swt/snippets/#opengl">OpenGL snippets</a> | |
31 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
32 * | |
29 * @since 3.2 | 33 * @since 3.2 |
30 */ | 34 */ |
31 | 35 |
32 public class GLCanvas : Canvas { | 36 public class GLCanvas : Canvas { |
33 NSOpenGLView glView; | 37 NSOpenGLView glView; |
50 public this (Composite parent, int style, GLData data) { | 54 public this (Composite parent, int style, GLData data) { |
51 super (parent, style); | 55 super (parent, style); |
52 if (data is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | 56 if (data is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); |
53 int attrib [] = new int [MAX_ATTRIBUTES]; | 57 int attrib [] = new int [MAX_ATTRIBUTES]; |
54 int pos = 0; | 58 int pos = 0; |
55 //TODO this is not working | 59 //TODO use color options |
56 // attrib [pos++] = OS.AGL_RGBA; | 60 // attrib [pos++] = OS.AGL_RGBA; |
57 if (data.doubleBuffer) attrib [pos++] = OS.NSOpenGLPFADoubleBuffer; | 61 if (data.doubleBuffer) attrib [pos++] = OS.NSOpenGLPFADoubleBuffer; |
58 if (data.stereo) attrib [pos++] = OS.NSOpenGLPFAStereo; | 62 if (data.stereo) attrib [pos++] = OS.NSOpenGLPFAStereo; |
59 // if (data.redSize > 0) { | 63 // if (data.redSize > 0) { |
60 // attrib [pos++] = OS.AGL_RED_SIZE; | 64 // attrib [pos++] = OS.AGL_RED_SIZE; |
115 glView = cast(NSOpenGLView)new NSOpenGLView().alloc(); | 119 glView = cast(NSOpenGLView)new NSOpenGLView().alloc(); |
116 if (glView is null) { | 120 if (glView is null) { |
117 dispose (); | 121 dispose (); |
118 DWT.error (DWT.ERROR_UNSUPPORTED_DEPTH); | 122 DWT.error (DWT.ERROR_UNSUPPORTED_DEPTH); |
119 } | 123 } |
120 glView.initWithFrame(parent.view.frame(), pixelFormat); | 124 glView.initWithFrame(parent.view.bounds(), pixelFormat); |
121 glView.setAutoresizingMask(OS.NSViewWidthSizable | OS.NSViewHeightSizable); | 125 glView.setAutoresizingMask(OS.NSViewWidthSizable | OS.NSViewHeightSizable); |
126 parent.view.addSubview(glView); | |
122 | 127 |
123 Listener listener = new Listener () { | 128 Listener listener = new Listener () { |
124 public void handleEvent (Event event) { | 129 public void handleEvent (Event event) { |
125 switch (event.type) { | 130 switch (event.type) { |
126 case DWT.Dispose: | 131 case DWT.Dispose: |
127 if (glView !is null) glView.release(); | 132 if (glView !is null) { |
128 glView = null; | 133 glView.clearGLContext(); |
129 if (pixelFormat !is null) pixelFormat.release(); | 134 glView.release(); |
130 pixelFormat = null; | 135 } |
131 break; | 136 glView = null; |
137 if (pixelFormat !is null) pixelFormat.release(); | |
138 pixelFormat = null; | |
139 break; | |
132 } | 140 } |
133 } | 141 } |
134 }; | 142 }; |
135 addListener (DWT.Dispose, listener); | 143 addListener (DWT.Dispose, listener); |
136 } | 144 } |
146 */ | 154 */ |
147 public GLData getGLData () { | 155 public GLData getGLData () { |
148 checkWidget (); | 156 checkWidget (); |
149 GLData data = new GLData (); | 157 GLData data = new GLData (); |
150 int [] value = new int [1]; | 158 int [] value = new int [1]; |
159 //TODO implement getGLData() | |
151 // AGL.aglDescribePixelFormat (pixelFormat, AGL.AGL_DOUBLEBUFFER, value); | 160 // AGL.aglDescribePixelFormat (pixelFormat, AGL.AGL_DOUBLEBUFFER, value); |
152 // data.doubleBuffer = value [0] !is 0; | 161 // data.doubleBuffer = value [0] !is 0; |
153 // AGL.aglDescribePixelFormat (pixelFormat, AGL.AGL_STEREO, value); | 162 // AGL.aglDescribePixelFormat (pixelFormat, AGL.AGL_STEREO, value); |
154 // data.stereo = value [0] !is 0; | 163 // data.stereo = value [0] !is 0; |
155 // AGL.aglDescribePixelFormat (pixelFormat, AGL.AGL_RED_SIZE, value); | 164 // AGL.aglDescribePixelFormat (pixelFormat, AGL.AGL_RED_SIZE, value); |