summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/windows/wgl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-10-30 17:32:02 +0100
committerSven Gothel <[email protected]>2012-10-30 17:32:02 +0100
commit24d5fa1241e17f596ae93dff1656a9317daf6fb3 (patch)
treeebdac54b377cfb77dee41536c266e4f4be4fdde6 /src/jogl/classes/jogamp/opengl/windows/wgl
parente5692f615a8c40e7ca750261baf5e8ecdb0a34b8 (diff)
WGL/WGLExt Robustness: Use NIODirectOnly for all bindings. For these internal APIs, critical array is not required, hence redundant.
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/windows/wgl')
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WGLGLCapabilities.java47
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java53
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java14
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java236
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java8
5 files changed, 188 insertions, 170 deletions
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WGLGLCapabilities.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WGLGLCapabilities.java
index 6a4ce5a4e..99064b123 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WGLGLCapabilities.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WGLGLCapabilities.java
@@ -28,6 +28,8 @@
package jogamp.opengl.windows.wgl;
+import java.nio.IntBuffer;
+
import jogamp.nativewindow.windows.GDI;
import jogamp.nativewindow.windows.PIXELFORMATDESCRIPTOR;
@@ -75,12 +77,13 @@ public class WGLGLCapabilities extends GLCapabilities {
return true;
}
- public boolean setValuesByARB(final int[] iattribs, final int niattribs, final int[] iresults) {
+ public boolean setValuesByARB(final IntBuffer iattribs, final int niattribs, final IntBuffer iresults) {
arb_pixelformat = 1;
int alphaBits = 0;
for (int i = 0; i < niattribs; i++) {
- int attr = iattribs[i];
+ final int attr = iattribs.get(i);
+ final int res = iresults.get(i);
switch (attr) {
case WGLExt.WGL_DRAW_TO_WINDOW_ARB:
case WGLExt.WGL_DRAW_TO_BITMAP_ARB:
@@ -88,37 +91,37 @@ public class WGLGLCapabilities extends GLCapabilities {
break;
case WGLExt.WGL_ACCELERATION_ARB:
- setHardwareAccelerated(iresults[i] == WGLExt.WGL_FULL_ACCELERATION_ARB);
+ setHardwareAccelerated(res == WGLExt.WGL_FULL_ACCELERATION_ARB);
break;
case WGLExt.WGL_SUPPORT_OPENGL_ARB:
- if (iresults[i] != GL.GL_TRUE) {
+ if (res != GL.GL_TRUE) {
return false;
}
break;
case WGLExt.WGL_DEPTH_BITS_ARB:
- setDepthBits(iresults[i]);
+ setDepthBits(res);
break;
case WGLExt.WGL_STENCIL_BITS_ARB:
- setStencilBits(iresults[i]);
+ setStencilBits(res);
break;
case WGLExt.WGL_DOUBLE_BUFFER_ARB:
- setDoubleBuffered(iresults[i] == GL.GL_TRUE);
+ setDoubleBuffered(res == GL.GL_TRUE);
break;
case WGLExt.WGL_STEREO_ARB:
- setStereo(iresults[i] == GL.GL_TRUE);
+ setStereo(res == GL.GL_TRUE);
break;
case WGLExt.WGL_PIXEL_TYPE_ARB:
- if(iresults[i] == WGLExt.WGL_TYPE_COLORINDEX_ARB) {
+ if(res == WGLExt.WGL_TYPE_COLORINDEX_ARB) {
return false; // color index not supported
}
- if (iresults[i] == WGLExt.WGL_TYPE_RGBA_FLOAT_ARB) {
+ if (res == WGLExt.WGL_TYPE_RGBA_FLOAT_ARB) {
setPbufferFloatingPointBuffers(true);
}
@@ -127,54 +130,54 @@ public class WGLGLCapabilities extends GLCapabilities {
break;
case WGLExt.WGL_FLOAT_COMPONENTS_NV:
- if (iresults[i] != 0) {
+ if (res != 0) {
setPbufferFloatingPointBuffers(true);
}
break;
case WGLExt.WGL_RED_BITS_ARB:
- setRedBits(iresults[i]);
+ setRedBits(res);
break;
case WGLExt.WGL_GREEN_BITS_ARB:
- setGreenBits(iresults[i]);
+ setGreenBits(res);
break;
case WGLExt.WGL_BLUE_BITS_ARB:
- setBlueBits(iresults[i]);
+ setBlueBits(res);
break;
case WGLExt.WGL_ALPHA_BITS_ARB:
// ALPHA shall be set at last - due to it's auto setting by !opaque / samples
- alphaBits = iresults[i];
+ alphaBits = res;
break;
case WGLExt.WGL_ACCUM_RED_BITS_ARB:
- setAccumRedBits(iresults[i]);
+ setAccumRedBits(res);
break;
case WGLExt.WGL_ACCUM_GREEN_BITS_ARB:
- setAccumGreenBits(iresults[i]);
+ setAccumGreenBits(res);
break;
case WGLExt.WGL_ACCUM_BLUE_BITS_ARB:
- setAccumBlueBits(iresults[i]);
+ setAccumBlueBits(res);
break;
case WGLExt.WGL_ACCUM_ALPHA_BITS_ARB:
- setAccumAlphaBits(iresults[i]);
+ setAccumAlphaBits(res);
break;
case WGLExt.WGL_SAMPLE_BUFFERS_ARB:
- setSampleBuffers(iresults[i] != 0);
+ setSampleBuffers(res != 0);
break;
case WGLExt.WGL_SAMPLES_ARB:
- setNumSamples(iresults[i]);
+ setNumSamples(res);
break;
default:
- throw new GLException("Unknown pixel format attribute " + iattribs[i]);
+ throw new GLException("Unknown pixel format attribute " + attr);
}
}
setAlphaBits(alphaBits);
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java
index 75c1c4441..7a512c85f 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java
@@ -40,6 +40,9 @@
package jogamp.opengl.windows.wgl;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeSurface;
import javax.media.nativewindow.NativeWindowException;
@@ -51,6 +54,8 @@ import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
+import com.jogamp.common.nio.Buffers;
+
import jogamp.nativewindow.windows.GDI;
import jogamp.opengl.GLDrawableImpl;
import jogamp.opengl.GLGraphicsConfigurationUtil;
@@ -131,8 +136,8 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
final int winattrPbuffer = GLGraphicsConfigurationUtil.getExclusiveWinAttributeBits(false /* onscreen */, false /* fbo */, true /* pbuffer */, false /* bitmap */);
- int[] iattributes = new int [2*WindowsWGLGraphicsConfiguration.MAX_ATTRIBS];
- float[] fattributes = new float[1];
+ final IntBuffer iattributes = Buffers.newDirectIntBuffer(2*WindowsWGLGraphicsConfiguration.MAX_ATTRIBS);
+ final FloatBuffer fattributes = Buffers.newDirectFloatBuffer(1);
int[] floatModeTmp = new int[1];
int niattribs = 0;
@@ -161,18 +166,14 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
ati = (floatMode == GLPbuffer.ATI_FLOAT);
} */
- int[] pformats = new int[WindowsWGLGraphicsConfiguration.MAX_PFORMATS];
- int nformats;
- int[] nformatsTmp = new int[1];
+ final IntBuffer pformats = Buffers.newDirectIntBuffer(WindowsWGLGraphicsConfiguration.MAX_PFORMATS);
+ final IntBuffer nformatsTmp = Buffers.newDirectIntBuffer(1);
if (!wglExt.wglChoosePixelFormatARB(sharedHdc,
- iattributes, 0,
- fattributes, 0,
- WindowsWGLGraphicsConfiguration.MAX_PFORMATS,
- pformats, 0,
- nformatsTmp, 0)) {
+ iattributes, fattributes, WindowsWGLGraphicsConfiguration.MAX_PFORMATS,
+ pformats, nformatsTmp)) {
throw new GLException("pbuffer creation error: wglChoosePixelFormat() failed");
}
- nformats = nformatsTmp[0];
+ final int nformats = nformatsTmp.get(0);
if (nformats <= 0) {
throw new GLException("pbuffer creation error: Couldn't find a suitable pixel format");
}
@@ -181,8 +182,8 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
System.err.println("" + nformats + " suitable pixel formats found");
for (int i = 0; i < nformats; i++) {
WGLGLCapabilities dbgCaps = WindowsWGLGraphicsConfiguration.wglARBPFID2GLCapabilities(sharedResource, device, glProfile,
- sharedHdc, pformats[i], winattrPbuffer);
- System.err.println("pixel format " + pformats[i] + " (index " + i + "): " + dbgCaps);
+ sharedHdc, pformats.get(i), winattrPbuffer);
+ System.err.println("pixel format " + pformats.get(i) + " (index " + i + "): " + dbgCaps);
}
}
@@ -192,32 +193,32 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
int whichFormat;
// Loop is a workaround for bugs in NVidia's recent drivers
for (whichFormat = 0; whichFormat < nformats; whichFormat++) {
- int format = pformats[whichFormat];
+ int format = pformats.get(whichFormat);
// Create the p-buffer.
niattribs = 0;
if (rtt) {
- iattributes[niattribs++] = WGLExt.WGL_TEXTURE_FORMAT_ARB;
+ iattributes.put(niattribs++, WGLExt.WGL_TEXTURE_FORMAT_ARB);
if (useFloat) {
- iattributes[niattribs++] = WGLExt.WGL_TEXTURE_FLOAT_RGB_NV;
+ iattributes.put(niattribs++, WGLExt.WGL_TEXTURE_FLOAT_RGB_NV);
} else {
- iattributes[niattribs++] = WGLExt.WGL_TEXTURE_RGBA_ARB;
+ iattributes.put(niattribs++, WGLExt.WGL_TEXTURE_RGBA_ARB);
}
- iattributes[niattribs++] = WGLExt.WGL_TEXTURE_TARGET_ARB;
- iattributes[niattribs++] = rect ? WGLExt.WGL_TEXTURE_RECTANGLE_NV : WGLExt.WGL_TEXTURE_2D_ARB;
+ iattributes.put(niattribs++, WGLExt.WGL_TEXTURE_TARGET_ARB);
+ iattributes.put(niattribs++, rect ? WGLExt.WGL_TEXTURE_RECTANGLE_NV : WGLExt.WGL_TEXTURE_2D_ARB);
- iattributes[niattribs++] = WGLExt.WGL_MIPMAP_TEXTURE_ARB;
- iattributes[niattribs++] = GL.GL_FALSE;
+ iattributes.put(niattribs++, WGLExt.WGL_MIPMAP_TEXTURE_ARB);
+ iattributes.put(niattribs++, GL.GL_FALSE);
- iattributes[niattribs++] = WGLExt.WGL_PBUFFER_LARGEST_ARB; // exact
- iattributes[niattribs++] = GL.GL_FALSE;
+ iattributes.put(niattribs++, WGLExt.WGL_PBUFFER_LARGEST_ARB); // exact
+ iattributes.put(niattribs++, GL.GL_FALSE);
}
- iattributes[niattribs++] = 0;
+ iattributes.put(niattribs++, 0);
- tmpBuffer = wglExt.wglCreatePbufferARB(sharedHdc, format, getWidth(), getHeight(), iattributes, 0);
+ tmpBuffer = wglExt.wglCreatePbufferARB(sharedHdc, format, getWidth(), getHeight(), iattributes);
if (tmpBuffer != 0) {
// Done
break;
@@ -228,7 +229,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
throw new GLException("pbuffer creation error: wglCreatePbuffer() failed: tried " + nformats +
" pixel formats, last error was: " + wglGetLastError());
}
- pfdid = pformats[whichFormat];
+ pfdid = pformats.get(whichFormat);
}
// Get the device context.
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java
index 8825bad0a..57f16522c 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java
@@ -41,6 +41,7 @@
package jogamp.opengl.windows.wgl;
import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
import java.util.HashMap;
import java.util.Map;
@@ -51,6 +52,7 @@ import javax.media.opengl.GLContext;
import javax.media.opengl.GLException;
import javax.media.opengl.GLCapabilitiesImmutable;
+import com.jogamp.common.nio.Buffers;
import com.jogamp.gluegen.runtime.ProcAddressTable;
import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver;
import com.jogamp.opengl.GLExtensions;
@@ -235,7 +237,8 @@ public class WindowsWGLContext extends GLContextImpl {
}
try {
- ctx = _wglExt.wglCreateContextAttribsARB(drawable.getHandle(), share, attribs, 0);
+ final IntBuffer attribsNIO = Buffers.newDirectIntBuffer(attribs);
+ ctx = _wglExt.wglCreateContextAttribsARB(drawable.getHandle(), share, attribsNIO);
} catch (RuntimeException re) {
if(DEBUG) {
Throwable t = new Throwable("Info: WindowWGLContext.createContextARBImpl wglCreateContextAttribsARB failed with "+getGLVersion(major, minor, ctp, "@creation"), re);
@@ -487,9 +490,12 @@ public class WindowsWGLContext extends GLContextImpl {
if (initSwapGroupImpl(wglExt)>0) {
final NativeSurface ns = drawable.getNativeSurface();
try {
- if( wglExt.wglQueryMaxSwapGroupsNV(ns.getDisplayHandle(),
- maxGroups, maxGroups_offset,
- maxBarriers, maxBarriers_offset) ) {
+ final IntBuffer maxGroupsNIO = Buffers.newDirectIntBuffer(maxGroups.length - maxGroups_offset);
+ final IntBuffer maxBarriersNIO = Buffers.newDirectIntBuffer(maxBarriers.length - maxBarriers_offset);
+
+ if( wglExt.wglQueryMaxSwapGroupsNV(ns.getDisplayHandle(), maxGroupsNIO, maxBarriersNIO) ) {
+ maxGroupsNIO.get(maxGroups, maxGroups_offset, maxGroupsNIO.remaining());
+ maxBarriersNIO.get(maxGroups, maxGroups_offset, maxBarriersNIO.remaining());
res = true;
}
} catch (Throwable t) { hasSwapGroupNV=-1; }
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java
index 058f4e336..70da1137d 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java
@@ -33,6 +33,8 @@
package jogamp.opengl.windows.wgl;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.List;
@@ -47,6 +49,7 @@ import javax.media.opengl.GLException;
import javax.media.opengl.GLPbuffer;
import javax.media.opengl.GLProfile;
+import com.jogamp.common.nio.Buffers;
import com.jogamp.nativewindow.MutableGraphicsConfiguration;
import com.jogamp.opengl.GLExtensions;
@@ -225,38 +228,38 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
public final int getPixelFormatID() { return isDetermined ? ((WGLGLCapabilities)capabilitiesChosen).getPFDID() : 0; }
public final boolean isChoosenByARB() { return isDetermined ? ((WGLGLCapabilities)capabilitiesChosen).isSetByARB() : false; }
- static int fillAttribsForGeneralWGLARBQuery(WindowsWGLDrawableFactory.SharedResource sharedResource, int[] iattributes) {
+ static int fillAttribsForGeneralWGLARBQuery(WindowsWGLDrawableFactory.SharedResource sharedResource, IntBuffer iattributes) {
int niattribs = 0;
- iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_WINDOW_ARB;
+ iattributes.put(niattribs++, WGLExt.WGL_DRAW_TO_WINDOW_ARB);
if(sharedResource.hasARBPBuffer()) {
- iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_PBUFFER_ARB;
- }
- iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_BITMAP_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ACCELERATION_ARB;
- iattributes[niattribs++] = WGLExt.WGL_SUPPORT_OPENGL_ARB;
- iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB;
- iattributes[niattribs++] = WGLExt.WGL_STEREO_ARB;
- iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB;
- iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB;
+ iattributes.put(niattribs++, WGLExt.WGL_DRAW_TO_PBUFFER_ARB);
+ }
+ iattributes.put(niattribs++, WGLExt.WGL_DRAW_TO_BITMAP_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_ACCELERATION_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_SUPPORT_OPENGL_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_DEPTH_BITS_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_STENCIL_BITS_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_DOUBLE_BUFFER_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_STEREO_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_PIXEL_TYPE_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_RED_BITS_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_GREEN_BITS_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_BLUE_BITS_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_ALPHA_BITS_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_ACCUM_RED_BITS_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_ACCUM_GREEN_BITS_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_ACCUM_BLUE_BITS_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_ACCUM_ALPHA_BITS_ARB);
if(sharedResource.hasARBMultisample()) {
- iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB;
+ iattributes.put(niattribs++, WGLExt.WGL_SAMPLE_BUFFERS_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_SAMPLES_ARB);
}
if(sharedResource.hasARBPBuffer()) {
GLContextImpl sharedCtx = sharedResource.getContext();
if(null != sharedCtx && sharedCtx.isExtensionAvailable(WindowsWGLDrawableFactory.WGL_NV_float_buffer)) {
// pbo float buffer
- iattributes[niattribs++] = WGLExt.WGL_FLOAT_COMPONENTS_NV; // nvidia
+ iattributes.put(niattribs++, WGLExt.WGL_FLOAT_COMPONENTS_NV); // nvidia
}
}
@@ -264,10 +267,10 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
}
static boolean wglARBPFIDValid(WindowsWGLContext sharedCtx, long hdc, int pfdID) {
- int[] in = new int[1];
- int[] out = new int[1];
- in[0] = WGLExt.WGL_COLOR_BITS_ARB;
- if (!sharedCtx.getWGLExt().wglGetPixelFormatAttribivARB(hdc, pfdID, 0, 1, in, 0, out, 0)) {
+ final IntBuffer out = Buffers.newDirectIntBuffer(1);
+ final IntBuffer in = Buffers.newDirectIntBuffer(1);
+ in.put(0, WGLExt.WGL_COLOR_BITS_ARB);
+ if (!sharedCtx.getWGLExt().wglGetPixelFormatAttribivARB(hdc, pfdID, 0, 1, in, out)) {
// Some GPU's falsely fails with a zero error code (success)
return GDI.GetLastError() == GDI.ERROR_SUCCESS ;
}
@@ -275,22 +278,22 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
}
static int wglARBPFDIDCount(WindowsWGLContext sharedCtx, long hdc) {
- int[] iattributes = new int[1];
- int[] iresults = new int[1];
+ final IntBuffer iresults = Buffers.newDirectIntBuffer(1);
+ final IntBuffer iattributes = Buffers.newDirectIntBuffer(1);
+ iattributes.put(0, WGLExt.WGL_NUMBER_PIXEL_FORMATS_ARB);
WGLExt wglExt = sharedCtx.getWGLExt();
- iattributes[0] = WGLExt.WGL_NUMBER_PIXEL_FORMATS_ARB;
// pfdID shall be ignored here (spec), however, pass a valid pdf index '1' below (possible driver bug)
- if (!wglExt.wglGetPixelFormatAttribivARB(hdc, 1 /* pfdID */, 0, 1, iattributes, 0, iresults, 0)) {
+ if (!wglExt.wglGetPixelFormatAttribivARB(hdc, 1 /* pfdID */, 0, 1, iattributes, iresults)) {
if(DEBUG) {
System.err.println("GetPixelFormatAttribivARB: Failed - HDC 0x" + Long.toHexString(hdc) +
- ", value "+iresults[0]+
+ ", value "+iresults.get(0)+
", LastError: " + GDI.GetLastError());
Thread.dumpStack();
}
return 0;
}
- final int pfdIDCount = iresults[0];
+ final int pfdIDCount = iresults.get(0);
if(0 == pfdIDCount) {
if(DEBUG) {
System.err.println("GetPixelFormatAttribivARB: No formats - HDC 0x" + Long.toHexString(hdc) +
@@ -316,12 +319,11 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
return null;
}
- int[] iattributes = new int [2*MAX_ATTRIBS];
- int[] iresults = new int [2*MAX_ATTRIBS];
+ final IntBuffer iattributes = Buffers.newDirectIntBuffer(2*MAX_ATTRIBS);
+ final IntBuffer iresults = Buffers.newDirectIntBuffer(2*MAX_ATTRIBS);
+ final int niattribs = fillAttribsForGeneralWGLARBQuery(sharedResource, iattributes);
- int niattribs = fillAttribsForGeneralWGLARBQuery(sharedResource, iattributes);
-
- if (!((WindowsWGLContext)sharedResource.getContext()).getWGLExt().wglGetPixelFormatAttribivARB(hdc, pfdID, 0, niattribs, iattributes, 0, iresults, 0)) {
+ if (!((WindowsWGLContext)sharedResource.getContext()).getWGLExt().wglGetPixelFormatAttribivARB(hdc, pfdID, 0, niattribs, iattributes, iresults)) {
throw new GLException("wglARBPFID2GLCapabilities: Error getting pixel format attributes for pixel format " + pfdID +
" of device context " + toHexString(hdc) + ", werr " + GDI.GetLastError());
}
@@ -330,7 +332,7 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
static int[] wglChoosePixelFormatARB(WindowsWGLDrawableFactory.SharedResource sharedResource, AbstractGraphicsDevice device,
GLCapabilitiesImmutable capabilities,
- long hdc, int[] iattributes, int accelerationMode, float[] fattributes)
+ long hdc, IntBuffer iattributes, int accelerationMode, FloatBuffer fattributes)
{
if ( !WindowsWGLGraphicsConfiguration.GLCapabilities2AttribList(capabilities,
@@ -343,24 +345,26 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
return null;
}
- int[] pformatsTmp = new int[WindowsWGLGraphicsConfiguration.MAX_PFORMATS];
- int[] numFormatsTmp = new int[1];
- if ( !((WindowsWGLContext)sharedResource.getContext()).getWGLExt().wglChoosePixelFormatARB(hdc, iattributes, 0,
- fattributes, 0,
- WindowsWGLGraphicsConfiguration.MAX_PFORMATS,
- pformatsTmp, 0, numFormatsTmp, 0))
- {
+ final WGLExt wglExt = ((WindowsWGLContext)sharedResource.getContext()).getWGLExt();
+ final IntBuffer pformatsTmp = Buffers.newDirectIntBuffer(WindowsWGLGraphicsConfiguration.MAX_PFORMATS);
+ final IntBuffer numFormatsTmp = Buffers.newDirectIntBuffer(1);
+
+ if ( !wglExt.wglChoosePixelFormatARB(hdc, iattributes, fattributes,
+ WindowsWGLGraphicsConfiguration.MAX_PFORMATS,
+ pformatsTmp, numFormatsTmp) ) {
if (DEBUG) {
System.err.println("wglChoosePixelFormatARB: wglChoosePixelFormatARB failed: " + GDI.GetLastError());
Thread.dumpStack();
}
return null;
}
- int numFormats = numFormatsTmp[0];
- int[] pformats = null;
+ final int numFormats = numFormatsTmp.get(0);
+ final int[] pformats;
if( 0 < numFormats ) {
pformats = new int[numFormats];
- System.arraycopy(pformatsTmp, 0, pformats, 0, numFormats);
+ pformatsTmp.get(pformats, 0, numFormats);
+ } else {
+ pformats = null;
}
if (DEBUG) {
System.err.println("wglChoosePixelFormatARB: NumFormats (wglChoosePixelFormatARB) accelMode 0x"
@@ -381,15 +385,15 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
}
final int numFormats = pfdIDs.length;
- int[] iattributes = new int [2*MAX_ATTRIBS];
- int[] iresults = new int [2*MAX_ATTRIBS];
- int niattribs = fillAttribsForGeneralWGLARBQuery(sharedResource, iattributes);
+ final IntBuffer iattributes = Buffers.newDirectIntBuffer(2*MAX_ATTRIBS);
+ final IntBuffer iresults = Buffers.newDirectIntBuffer(2*MAX_ATTRIBS);
+ final int niattribs = fillAttribsForGeneralWGLARBQuery(sharedResource, iattributes);
ArrayList<GLCapabilitiesImmutable> bucket = new ArrayList<GLCapabilitiesImmutable>();
for(int i = 0; i<numFormats; i++) {
if ( pfdIDs[i] >= 1 &&
- ((WindowsWGLContext)sharedResource.getContext()).getWGLExt().wglGetPixelFormatAttribivARB(hdc, pfdIDs[i], 0, niattribs, iattributes, 0, iresults, 0) ) {
+ ((WindowsWGLContext)sharedResource.getContext()).getWGLExt().wglGetPixelFormatAttribivARB(hdc, pfdIDs[i], 0, niattribs, iattributes, iresults) ) {
final GLCapabilitiesImmutable caps = AttribList2GLCapabilities(device, glp, hdc, pfdIDs[i], iattributes, niattribs, iresults, winattrbits);
if(null != caps) {
bucket.add(caps);
@@ -414,21 +418,21 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
}
static boolean GLCapabilities2AttribList(GLCapabilitiesImmutable caps,
- int[] iattributes,
+ IntBuffer iattributes,
WindowsWGLDrawableFactory.SharedResource sharedResource,
int accelerationValue,
- int[] floatMode) throws GLException {
+ int[] floatMode) throws GLException {
if (!sharedResource.hasARBPixelFormat()) {
return false;
}
int niattribs = 0;
- iattributes[niattribs++] = WGLExt.WGL_SUPPORT_OPENGL_ARB;
- iattributes[niattribs++] = GL.GL_TRUE;
+ iattributes.put(niattribs++, WGLExt.WGL_SUPPORT_OPENGL_ARB);
+ iattributes.put(niattribs++, GL.GL_TRUE);
if(accelerationValue>0) {
- iattributes[niattribs++] = WGLExt.WGL_ACCELERATION_ARB;
- iattributes[niattribs++] = accelerationValue;
+ iattributes.put(niattribs++, WGLExt.WGL_ACCELERATION_ARB);
+ iattributes.put(niattribs++, accelerationValue);
}
final boolean usePBuffer = caps.isPBuffer() && sharedResource.hasARBPBuffer() ;
@@ -445,63 +449,63 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
} else {
throw new GLException("no surface type set in caps: "+caps);
}
- iattributes[niattribs++] = surfaceType;
- iattributes[niattribs++] = GL.GL_TRUE;
+ iattributes.put(niattribs++, surfaceType);
+ iattributes.put(niattribs++, GL.GL_TRUE);
- iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB;
+ iattributes.put(niattribs++, WGLExt.WGL_DOUBLE_BUFFER_ARB);
if (caps.getDoubleBuffered()) {
- iattributes[niattribs++] = GL.GL_TRUE;
+ iattributes.put(niattribs++, GL.GL_TRUE);
} else {
- iattributes[niattribs++] = GL.GL_FALSE;
+ iattributes.put(niattribs++, GL.GL_FALSE);
}
- iattributes[niattribs++] = WGLExt.WGL_STEREO_ARB;
+ iattributes.put(niattribs++, WGLExt.WGL_STEREO_ARB);
if (caps.getStereo()) {
- iattributes[niattribs++] = GL.GL_TRUE;
+ iattributes.put(niattribs++, GL.GL_TRUE);
} else {
- iattributes[niattribs++] = GL.GL_FALSE;
+ iattributes.put(niattribs++, GL.GL_FALSE);
}
- iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB;
- iattributes[niattribs++] = caps.getRedBits();
- iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB;
- iattributes[niattribs++] = caps.getGreenBits();
- iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB;
- iattributes[niattribs++] = caps.getBlueBits();
+ iattributes.put(niattribs++, WGLExt.WGL_RED_BITS_ARB);
+ iattributes.put(niattribs++, caps.getRedBits());
+ iattributes.put(niattribs++, WGLExt.WGL_GREEN_BITS_ARB);
+ iattributes.put(niattribs++, caps.getGreenBits());
+ iattributes.put(niattribs++, WGLExt.WGL_BLUE_BITS_ARB);
+ iattributes.put(niattribs++, caps.getBlueBits());
if(caps.getAlphaBits()>0) {
- iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB;
- iattributes[niattribs++] = caps.getAlphaBits();
+ iattributes.put(niattribs++, WGLExt.WGL_ALPHA_BITS_ARB);
+ iattributes.put(niattribs++, caps.getAlphaBits());
}
if(caps.getStencilBits()>0) {
- iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB;
- iattributes[niattribs++] = caps.getStencilBits();
+ iattributes.put(niattribs++, WGLExt.WGL_STENCIL_BITS_ARB);
+ iattributes.put(niattribs++, caps.getStencilBits());
}
- iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB;
- iattributes[niattribs++] = caps.getDepthBits();
+ iattributes.put(niattribs++, WGLExt.WGL_DEPTH_BITS_ARB);
+ iattributes.put(niattribs++, caps.getDepthBits());
if (caps.getAccumRedBits() > 0 ||
caps.getAccumGreenBits() > 0 ||
caps.getAccumBlueBits() > 0 ||
caps.getAccumAlphaBits() > 0) {
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_BITS_ARB;
- iattributes[niattribs++] = (caps.getAccumRedBits() +
- caps.getAccumGreenBits() +
- caps.getAccumBlueBits() +
- caps.getAccumAlphaBits());
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS_ARB;
- iattributes[niattribs++] = caps.getAccumRedBits();
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB;
- iattributes[niattribs++] = caps.getAccumGreenBits();
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB;
- iattributes[niattribs++] = caps.getAccumBlueBits();
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB;
- iattributes[niattribs++] = caps.getAccumAlphaBits();
+ iattributes.put(niattribs++, WGLExt.WGL_ACCUM_BITS_ARB);
+ iattributes.put(niattribs++, ( caps.getAccumRedBits() +
+ caps.getAccumGreenBits() +
+ caps.getAccumBlueBits() +
+ caps.getAccumAlphaBits() ) );
+ iattributes.put(niattribs++, WGLExt.WGL_ACCUM_RED_BITS_ARB);
+ iattributes.put(niattribs++, caps.getAccumRedBits());
+ iattributes.put(niattribs++, WGLExt.WGL_ACCUM_GREEN_BITS_ARB);
+ iattributes.put(niattribs++, caps.getAccumGreenBits());
+ iattributes.put(niattribs++, WGLExt.WGL_ACCUM_BLUE_BITS_ARB);
+ iattributes.put(niattribs++, caps.getAccumBlueBits());
+ iattributes.put(niattribs++, WGLExt.WGL_ACCUM_ALPHA_BITS_ARB);
+ iattributes.put(niattribs++, caps.getAccumAlphaBits());
}
if (caps.getSampleBuffers() && sharedResource.hasARBMultisample()) {
- iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB;
- iattributes[niattribs++] = GL.GL_TRUE;
- iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB;
- iattributes[niattribs++] = caps.getNumSamples();
+ iattributes.put(niattribs++, WGLExt.WGL_SAMPLE_BUFFERS_ARB);
+ iattributes.put(niattribs++, GL.GL_TRUE);
+ iattributes.put(niattribs++, WGLExt.WGL_SAMPLES_ARB);
+ iattributes.put(niattribs++, caps.getNumSamples());
}
boolean rtt = caps.getPbufferRenderToTexture();
@@ -547,22 +551,22 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
if (rtt) {
throw new GLException("Render-to-floating-point-texture not supported on ATI hardware");
} else {
- iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB;
- iattributes[niattribs++] = WGLExt.WGL_TYPE_RGBA_FLOAT_ARB;
+ iattributes.put(niattribs++, WGLExt.WGL_PIXEL_TYPE_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_TYPE_RGBA_FLOAT_ARB);
}
} else {
if (!rtt) {
// Currently we don't support non-truecolor visuals in the
// GLCapabilities, so we don't offer the option of making
// color-index pbuffers.
- iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB;
- iattributes[niattribs++] = WGLExt.WGL_TYPE_RGBA_ARB;
+ iattributes.put(niattribs++, WGLExt.WGL_PIXEL_TYPE_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_TYPE_RGBA_ARB);
}
}
if (useFloat && nvidia) {
- iattributes[niattribs++] = WGLExt.WGL_FLOAT_COMPONENTS_NV;
- iattributes[niattribs++] = GL.GL_TRUE;
+ iattributes.put(niattribs++, WGLExt.WGL_FLOAT_COMPONENTS_NV);
+ iattributes.put(niattribs++, GL.GL_TRUE);
}
if (rtt) {
@@ -572,42 +576,42 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
if (!rect) {
throw new GLException("Render-to-floating-point-texture only supported on NVidia hardware with render-to-texture-rectangle");
}
- iattributes[niattribs++] = WGLExt.WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV;
- iattributes[niattribs++] = GL.GL_TRUE;
+ iattributes.put(niattribs++, WGLExt.WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV);
+ iattributes.put(niattribs++, GL.GL_TRUE);
} else {
- iattributes[niattribs++] = rect ? WGLExt.WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV : WGLExt.WGL_BIND_TO_TEXTURE_RGB_ARB;
- iattributes[niattribs++] = GL.GL_TRUE;
+ iattributes.put(niattribs++, rect ? WGLExt.WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV : WGLExt.WGL_BIND_TO_TEXTURE_RGB_ARB);
+ iattributes.put(niattribs++, GL.GL_TRUE);
}
}
} else {
- iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB;
- iattributes[niattribs++] = WGLExt.WGL_TYPE_RGBA_ARB;
+ iattributes.put(niattribs++, WGLExt.WGL_PIXEL_TYPE_ARB);
+ iattributes.put(niattribs++, WGLExt.WGL_TYPE_RGBA_ARB);
}
- iattributes[niattribs++] = 0;
+ iattributes.put(niattribs++, 0);
return true;
}
- static int AttribList2DrawableTypeBits(final int[] iattribs,
- final int niattribs, final int[] iresults) {
+ static int AttribList2DrawableTypeBits(final IntBuffer iattribs,
+ final int niattribs, final IntBuffer iresults) {
int val = 0;
for (int i = 0; i < niattribs; i++) {
- int attr = iattribs[i];
+ final int attr = iattribs.get(i);
switch (attr) {
case WGLExt.WGL_DRAW_TO_WINDOW_ARB:
- if(iresults[i] == GL.GL_TRUE) {
+ if(iresults.get(i) == GL.GL_TRUE) {
val |= GLGraphicsConfigurationUtil.WINDOW_BIT |
GLGraphicsConfigurationUtil.FBO_BIT;
}
break;
case WGLExt.WGL_DRAW_TO_BITMAP_ARB:
- if(iresults[i] == GL.GL_TRUE) {
+ if(iresults.get(i) == GL.GL_TRUE) {
val |= GLGraphicsConfigurationUtil.BITMAP_BIT;
}
break;
case WGLExt.WGL_DRAW_TO_PBUFFER_ARB:
- if(iresults[i] == GL.GL_TRUE) {
+ if(iresults.get(i) == GL.GL_TRUE) {
val |= GLGraphicsConfigurationUtil.PBUFFER_BIT;
}
break;
@@ -618,7 +622,7 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio
static WGLGLCapabilities AttribList2GLCapabilities(final AbstractGraphicsDevice device,
final GLProfile glp, final long hdc, final int pfdID,
- final int[] iattribs, final int niattribs, final int[] iresults, final int winattrmask) {
+ final IntBuffer iattribs, final int niattribs, IntBuffer iresults, final int winattrmask) {
final int allDrawableTypeBits = AttribList2DrawableTypeBits(iattribs, niattribs, iresults);
int drawableTypeBits = winattrmask & allDrawableTypeBits;
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
index 10d7fb22b..7b3bc3a01 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
@@ -50,12 +50,16 @@ import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
+import com.jogamp.common.nio.Buffers;
+
import jogamp.nativewindow.windows.GDI;
import jogamp.nativewindow.windows.PIXELFORMATDESCRIPTOR;
import jogamp.opengl.GLDrawableImpl;
import jogamp.opengl.GLGraphicsConfigurationFactory;
import jogamp.opengl.GLGraphicsConfigurationUtil;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -349,8 +353,8 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat
// No given PFD IDs
//
// 1st choice: get GLCapabilities based on users GLCapabilities setting recommendedIndex as preferred choice
- int[] iattributes = new int[2 * WindowsWGLGraphicsConfiguration.MAX_ATTRIBS];
- float[] fattributes = new float[1];
+ final IntBuffer iattributes = Buffers.newDirectIntBuffer(2*WindowsWGLGraphicsConfiguration.MAX_ATTRIBS);
+ final FloatBuffer fattributes = Buffers.newDirectFloatBuffer(1);
int accelerationMode = WGLExt.WGL_FULL_ACCELERATION_ARB;
pformats = WindowsWGLGraphicsConfiguration.wglChoosePixelFormatARB(sharedResource, device, capsChosen,
hdc, iattributes, accelerationMode, fattributes);