From 45fa88a5904d3740313bd86b7837f21b3c27ca7f Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Thu, 29 May 2008 12:24:38 +0000 Subject: Made call to ByteOrder.nativeOrder() in BufferUtil reflective so it can be done when running on Java SE even if the code is compiled on CDC/FP. Fixed bug in WindowsWindow.c where upcalls from native WndProc were not being made. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1647 232f8b59-042b-4e1e-8c03-345bb8c30851 --- src/classes/com/sun/opengl/util/BufferUtil.java | 39 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'src/classes') diff --git a/src/classes/com/sun/opengl/util/BufferUtil.java b/src/classes/com/sun/opengl/util/BufferUtil.java index 756f568b4..392a03974 100755 --- a/src/classes/com/sun/opengl/util/BufferUtil.java +++ b/src/classes/com/sun/opengl/util/BufferUtil.java @@ -42,6 +42,8 @@ package com.sun.opengl.util; import java.nio.*; import java.util.*; +import java.lang.reflect.*; + /** Utility routines for dealing with direct buffers. */ public class BufferUtil { @@ -82,8 +84,7 @@ public class BufferUtil { the host platform's native byte order. */ public static ByteBuffer newByteBuffer(int numElements) { ByteBuffer bb = ByteBuffer.allocateDirect(numElements); - // FIXME: refactor dependencies on Java SE buffer classes - // bb.order(ByteOrder.nativeOrder()); + nativeOrder(bb); return bb; } @@ -228,4 +229,38 @@ public class BufferUtil { // dest.rewind(); // return dest; // } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + // NOTE that this work must be done reflectively at the present time + // because this code must compile and run correctly on both CDC/FP and J2SE + private static boolean isCDCFP; + private static Class byteOrderClass; + private static Object nativeOrderObject; + private static Method orderMethod; + + private static void nativeOrder(ByteBuffer buf) { + if (!isCDCFP) { + try { + if (byteOrderClass == null) { + byteOrderClass = Class.forName("java.nio.ByteOrder"); + orderMethod = ByteBuffer.class.getMethod("order", new Class[] { byteOrderClass }); + Method nativeOrderMethod = byteOrderClass.getMethod("nativeOrder", null); + nativeOrderObject = nativeOrderMethod.invoke(null, null); + } + } catch (Throwable t) { + // Must be running on CDC / FP + isCDCFP = true; + } + + if (!isCDCFP) { + try { + orderMethod.invoke(buf, new Object[] { nativeOrderObject }); + } catch (Throwable t) { + } + } + } + } } -- cgit v1.2.3