|
36 | 36 | import java.io.FileInputStream; |
37 | 37 | import java.io.IOException; |
38 | 38 | import java.io.InputStream; |
| 39 | +import java.lang.reflect.Method; |
39 | 40 | import java.nio.ByteBuffer; |
40 | 41 | import java.util.HashMap; |
41 | 42 | import java.util.Map; |
|
74 | 75 | import processing.core.PSurface; |
75 | 76 | import processing.event.KeyEvent; |
76 | 77 | import processing.event.MouseEvent; |
77 | | -import sun.java2d.opengl.CGLGraphicsConfig; |
78 | | -import sun.java2d.pipe.hw.ContextCapabilities; |
79 | 78 |
|
80 | 79 |
|
81 | 80 | public class PSurfaceJOGL implements PSurface { |
@@ -126,7 +125,7 @@ public class PSurfaceJOGL implements PSurface { |
126 | 125 | * Contains information about the environments on which FBO should NOT be used. |
127 | 126 | * Each position of the array contains a pair of {@link String}s correspondent to |
128 | 127 | * the operating system (based on {@link PConstants}) and the name of the |
129 | | - * hardware (based on {@link ContextCapabilities#adapterId}), respectively. |
| 128 | + * hardware (based on sun.java2d.pipe.hw.ContextCapabilities#adapterId), respectively. |
130 | 129 | */ |
131 | 130 | final protected String[][] antiFboEnvironments = new String[][]{ |
132 | 131 | {String.valueOf(PConstants.MACOSX), "Intel HD Graphics 3000"} |
@@ -208,20 +207,43 @@ protected void initDisplay() { |
208 | 207 | * If in future this resource must be used by other platforms, the main 'if' clause |
209 | 208 | * should be removed, allowing direct access to its inner logic. |
210 | 209 | */ |
211 | | - private void initFboControl(GraphicsConfiguration config){ |
212 | | - if(PApplet.platform == PApplet.MACOSX){ |
213 | | - for(String[] pair : antiFboEnvironments){ |
214 | | - if(pair[0].equals(String.valueOf(PApplet.platform))){ |
215 | | - String adapterId = ((CGLGraphicsConfig) config).getContextCapabilities().getAdapterId(); |
216 | | - if(adapterId.toLowerCase().contains(pair[1].toLowerCase())){ |
217 | | - this.fboAllowed = false; |
218 | | - break; |
| 210 | + private void initFboControl(GraphicsConfiguration config) { |
| 211 | + if (PApplet.platform == PApplet.MACOSX) { |
| 212 | + try { |
| 213 | + String adapterId = getAdapterId(config); |
| 214 | + for (String[] pair : antiFboEnvironments) { |
| 215 | + if (pair[0].equals(String.valueOf(PApplet.platform))) { |
| 216 | + if (adapterId.toLowerCase().contains(pair[1].toLowerCase())) { |
| 217 | + this.fboAllowed = false; |
| 218 | + break; |
| 219 | + } |
219 | 220 | } |
220 | 221 | } |
| 222 | + } catch (Exception e) { |
| 223 | + e.printStackTrace(); |
221 | 224 | } |
222 | 225 | } |
223 | 226 | } |
224 | 227 |
|
| 228 | + /** |
| 229 | + * Evaluates the graphics configuration through reflection to safely get the adapter |
| 230 | + * id from the hardware detected. |
| 231 | + * |
| 232 | + * @param config graphics configuration |
| 233 | + * @return the name of the adapter id as a String |
| 234 | + * @throws Exception when there is a problem with reflection |
| 235 | + */ |
| 236 | + private String getAdapterId(GraphicsConfiguration config) throws Exception { |
| 237 | + Class cglClass = Class.forName("sun.java2d.opengl.CGLGraphicsConfig"); |
| 238 | + Class ctcClass = Class.forName("sun.java2d.pipe.hw.ContextCapabilities"); |
| 239 | + Method cglMethod = cglClass.getMethod("getContextCapabilities"); |
| 240 | + Method ctcMethod = ctcClass.getMethod("getAdapterId"); |
| 241 | + Object cglInstance = cglClass.cast(config); |
| 242 | + Object ctcInstance = cglMethod.invoke(cglInstance); |
| 243 | + Object idInstance = ctcMethod.invoke(ctcInstance); |
| 244 | + return String.valueOf(idInstance); |
| 245 | + } |
| 246 | + |
225 | 247 | @Override |
226 | 248 | public boolean isFboAllowed(){ |
227 | 249 | return this.fboAllowed; |
|
0 commit comments