From 3d36ce1bac06911920714bd3e801002c0f533f68 Mon Sep 17 00:00:00 2001 From: kbr Date: Fri, 29 Jun 2007 00:15:57 +0000 Subject: Incorporated changes from Ultraq on javagaming.org forums for properly looking up EFX entry points git-svn-id: file:///home/mbien/NetBeansProjects/JOGAMP/joal-sync/git-svn/../svn-server-sync/joal/trunk@557 03bf7f67-59de-4072-a415-9a990d468a3f --- .../java/games/joal/impl/ALProcAddressLookup.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/java/net/java/games/joal/impl/ALProcAddressLookup.java b/src/java/net/java/games/joal/impl/ALProcAddressLookup.java index 5a188c7..c7bdc53 100755 --- a/src/java/net/java/games/joal/impl/ALProcAddressLookup.java +++ b/src/java/net/java/games/joal/impl/ALProcAddressLookup.java @@ -33,6 +33,8 @@ package net.java.games.joal.impl; +import java.lang.reflect.Field; + import net.java.games.joal.*; import com.sun.gluegen.runtime.*; @@ -80,6 +82,13 @@ public class ALProcAddressLookup { // per-ALcontext ALProcAddressTables and per-ALCdevice // ALCProcAddressTables. ProcAddressHelper.resetProcAddressTable(alTable, lookup); + + // The above only manages to find addresses for the core OpenAL + // functions. The below uses alGetProcAddress() to find the addresses + // of extensions such as EFX, just as in the C++ examples of the + // OpenAL 1.1 SDK. + useALGetProcAddress(); + alTableInitialized = true; } } @@ -111,4 +120,40 @@ public class ALProcAddressLookup { public static ALCProcAddressTable getALCProcAddressTable() { return alcTable; } + + + /** + * Retrieves the values of the OpenAL functions using alGetProcAddress(). + */ + private static void useALGetProcAddress() { + String addrOfPrefix = "_addressof_"; + ALImpl al = (ALImpl) ALFactory.getAL(); + + Field[] fields = ALProcAddressTable.class.getFields(); + for (int i = 0; i < fields.length; i++) { + Field field = fields[i]; + + // Skip non-address fields + String fieldname = field.getName(); + if (!fieldname.startsWith(addrOfPrefix)) { + continue; + } + try { + String functionname = fieldname.substring(addrOfPrefix.length()); + long fieldval = field.getLong(alTable); + + // Skip fields which have already been valued + if (fieldval != 0) { + continue; + } + + // Get the address + long procAddressVal = al.alGetProcAddress(functionname); + field.setLong(alTable, procAddressVal); + } + catch (Exception ex) { + throw new RuntimeException("Unable to repopulate ALProcAddressTable values", ex); + } + } + } } -- cgit v1.2.3