diff options
Diffstat (limited to 'src/jogl/classes/com/jogamp/gluegen/opengl')
-rw-r--r-- | src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java b/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java index 809c6783d..356482581 100644 --- a/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java @@ -39,6 +39,7 @@ */ package com.jogamp.gluegen.opengl; +import com.jogamp.common.util.SecurityUtil; import com.jogamp.gluegen.ConstantDefinition; import com.jogamp.gluegen.FunctionEmitter; import com.jogamp.gluegen.GlueEmitterControls; @@ -454,30 +455,53 @@ public class GLEmitter extends ProcAddressEmitter { return (GLConfiguration) getConfig(); } + /** + * {@inheritDoc} + */ @Override protected void endProcAddressTable() throws Exception { PrintWriter w = tableWriter; - w.println(" /**"); - w.println(" * This is a convenience method to get (by name) the native function"); - w.println(" * pointer for a given function. It lets you avoid having to"); - w.println(" * manually compute the "" + PROCADDRESS_VAR_PREFIX + " + "); - w.println(" * <functionName>" member variable name and look it up via"); - w.println(" * reflection; it also will throw an exception if you try to get the"); - w.println(" * address of an unknown function, or one that is statically linked"); - w.println(" * and therefore does not have a function pointer in this table."); - w.println(" *"); - w.println(" * @throws RuntimeException if the function pointer was not found in"); - w.println(" * this table, either because the function was unknown or because"); - w.println(" * it was statically linked."); - w.println(" */"); - w.println(" public long getAddressFor(String functionNameUsr) {"); - w.println(" String functionNameBase = "+GLNameResolver.class.getName()+".normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLNameResolver.normalizeARB(functionNameUsr, true), true);"); - w.println(" String addressFieldNameBase = PROCADDRESS_VAR_PREFIX + functionNameBase;"); + w.println(" @Override"); + w.println(" protected boolean isFunctionAvailableImpl(String functionNameUsr) throws IllegalArgumentException {"); + w.println(" final String functionNameBase = "+GLNameResolver.class.getName()+".normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLNameResolver.normalizeARB(functionNameUsr, true), true);"); + w.println(" final String addressFieldNameBase = \"" + PROCADDRESS_VAR_PREFIX + "\" + functionNameBase;"); w.println(" java.lang.reflect.Field addressField = null;"); w.println(" int funcNamePermNum = "+GLNameResolver.class.getName()+".getFuncNamePermutationNumber(functionNameBase);"); w.println(" for(int i = 0; null==addressField && i < funcNamePermNum; i++) {"); - w.println(" String addressFieldName = "+GLNameResolver.class.getName()+".getFuncNamePermutation(addressFieldNameBase, i);"); + w.println(" final String addressFieldName = "+GLNameResolver.class.getName()+".getFuncNamePermutation(addressFieldNameBase, i);"); + w.println(" try {"); + w.println(" addressField = getClass().getField(addressFieldName);"); + w.println(" } catch (Exception e) { }"); + w.println(" }"); + w.println(); + w.println(" if(null==addressField) {"); + w.println(" // The user is calling a bogus function or one which is not"); + w.println(" // runtime linked"); + w.println(" throw new RuntimeException("); + w.println(" \"WARNING: Address field query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); + w.println(" \"\\\"; it's either statically linked or address field is not a known \" +"); + w.println(" \"function\");"); + w.println(" } "); + w.println(" try {"); + w.println(" return 0 != addressField.getLong(this);"); + w.println(" } catch (Exception e) {"); + w.println(" throw new RuntimeException("); + w.println(" \"WARNING: Address query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); + w.println(" \"\\\"; it's either statically linked or is not a known \" +"); + w.println(" \"function\", e);"); + w.println(" }"); + w.println(" }"); + + w.println(" @Override"); + w.println(" public long getAddressFor(String functionNameUsr) throws SecurityException, IllegalArgumentException {"); + w.println(" SecurityUtil.checkAllLinkPermission();"); + w.println(" final String functionNameBase = "+GLNameResolver.class.getName()+".normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLNameResolver.normalizeARB(functionNameUsr, true), true);"); + w.println(" final String addressFieldNameBase = \"" + PROCADDRESS_VAR_PREFIX + "\" + functionNameBase;"); + w.println(" java.lang.reflect.Field addressField = null;"); + w.println(" int funcNamePermNum = "+GLNameResolver.class.getName()+".getFuncNamePermutationNumber(functionNameBase);"); + w.println(" for(int i = 0; null==addressField && i < funcNamePermNum; i++) {"); + w.println(" final String addressFieldName = "+GLNameResolver.class.getName()+".getFuncNamePermutation(addressFieldNameBase, i);"); w.println(" try {"); w.println(" addressField = getClass().getField(addressFieldName);"); w.println(" } catch (Exception e) { }"); |