public CrustLayer(AVList params) { URL url = null; try { URL context = (URL) params.getValue(AVKeyMore.CONTEXT_URL); url = new URL(context, params.getStringValue(AVKey.URL)); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } this.url = url; this.width = (Integer) params.getValue(AVKey.WIDTH); this.height = (Integer) params.getValue(AVKey.HEIGHT); this.sector = (Sector) params.getValue(AVKey.SECTOR); if (width <= 1 || height <= 1) { throw new IllegalArgumentException("Illegal width or height"); } double scale = 1; if (params.getValue(AVKeyMore.SCALE) != null) { scale = (Double) params.getValue(AVKeyMore.SCALE); } this.scale = scale; boolean wrap = false; if (params.getValue(AVKeyMore.WRAP) != null) { wrap = (Boolean) params.getValue(AVKeyMore.WRAP); } indices = generateTriStripIndices(width, height, wrap); vertices = Buffers.newDirectDoubleBuffer(width * height * 3); colors = Buffers.newDirectDoubleBuffer(width * height * 4); }
/** * Entry point to C language function: <code> * GLint {@native gluBuild1DMipmapLevels}(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data) * </code> <br> * Part of <code>GLU_VERSION_1_X</code><br> * * @param data a direct or array-backed {@link java.nio.Buffer} */ private int gluBuild1DMipmapLevelsC( int target, int internalFormat, int width, int format, int type, int level, int base, int max, Buffer data) { final boolean data_is_direct = Buffers.isDirect(data); final long __addr_ = getGLUProcAddressTable()._addressof_gluBuild1DMipmapLevels; if (__addr_ == 0) { throw new GLException(String.format("Method \"%s\" not available", "gluBuild1DMipmapLevels")); } return dispatch_gluBuild1DMipmapLevelsC1( target, internalFormat, width, format, type, level, base, max, data_is_direct ? data : Buffers.getArray(data), data_is_direct ? Buffers.getDirectBufferByteOffset(data) : Buffers.getIndirectBufferByteOffset(data), data_is_direct, __addr_); }
protected int updateCoordinateBuffers(TaggedAxis1D taggedAxis, int width, int height) { List<Tag> tags = taggedAxis.getSortedTags(); int size = tags.size(); if (vertexCoords == null || vertexCoords.capacity() < size * 4) vertexCoords = Buffers.newDirectFloatBuffer(size * 4); if (textureCoords == null || textureCoords.capacity() < size * 2) textureCoords = Buffers.newDirectFloatBuffer(size * 2); vertexCoords.rewind(); textureCoords.rewind(); int x1 = getColorBarMinX(width); int x2 = getColorBarMaxX(width); int count = 0; for (Tag tag : tags) { if (tag.hasAttribute(TEX_COORD_ATTR)) { float textureCoord = tag.getAttributeFloat(TEX_COORD_ATTR); float vertexCoord = (float) taggedAxis.valueToScreenPixel(tag.getValue()); vertexCoords.put(x1).put(vertexCoord).put(x2).put(vertexCoord); textureCoords.put(textureCoord).put(textureCoord); count += 2; } } return count; }
/** * Constructor that creates a Vertex Buffer Object with the specified GLSL attributes. (typically * location, texture coordinates, normals, etc.) * * @param gl The global openGL instance. * @param attribs One or more attributes that represent this VBO, @see GLSLAttrib */ public VBO(GL3 gl, GLSLAttrib... attribs) { this.attribs = attribs; // Generate a new internal OpenGL VBO pointer this.vboPointer = Buffers.newDirectIntBuffer(1); gl.glGenVertexArrays(1, this.vboPointer); gl.glBindVertexArray(this.vboPointer.get(0)); // Generate a new internal OpenGL Array Buffer pointer this.bufferPointer = Buffers.newDirectIntBuffer(1); gl.glGenBuffers(1, this.bufferPointer); gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, this.bufferPointer.get(0)); // Allocate enough memory int size = 0; for (final GLSLAttrib attrib : attribs) { size += attrib.buffer.capacity() * Buffers.SIZEOF_FLOAT; } gl.glBufferData(GL3.GL_ARRAY_BUFFER, size, (Buffer) null, GL3.GL_STATIC_DRAW); // Copy the GLSL Attribute data into the internal OpenGL buffer int nextStart = 0; for (final GLSLAttrib attrib : attribs) { gl.glBufferSubData( GL3.GL_ARRAY_BUFFER, nextStart, attrib.buffer.capacity() * Buffers.SIZEOF_FLOAT, attrib.buffer); nextStart += attrib.buffer.capacity() * Buffers.SIZEOF_FLOAT; } }
@Override protected final Buffer getGammaRamp(final NativeSurface surface) { final long display = surface.getDisplayHandle(); if (0 == display) { return null; } final int screenIdx = surface.getScreenIndex(); final int size = getGammaRampLength(surface); final ShortBuffer rampData = Buffers.newDirectShortBuffer(3 * size); final ShortBuffer redRampData = Buffers.slice(rampData, 0 * size, size); final ShortBuffer greenRampData = Buffers.slice(rampData, 1 * size, size); final ShortBuffer blueRampData = Buffers.slice(rampData, 2 * size, size); final boolean res = X11Lib.XF86VidModeGetGammaRamp( display, screenIdx, size, redRampData, greenRampData, blueRampData); if (!res) { return null; } if (DEBUG) { dumpRamp("GET__", size, redRampData, greenRampData, blueRampData); } return rampData; }
public void loadBuffers() { SurfCell curSurf; // the current surface being worked with PolyCell curPoly; // the current polygon in the surface VertListCell curVertLC; curSurf = surfHead; int vertCount; while (curSurf != null) { int vertsPerPrim; vertCount = 0; curPoly = curSurf.polyHead; // vertCount += curPoly.numVerts; vertsPerPrim = curPoly.numVerts; while (curPoly != null) { vertCount += curPoly.numVerts; if (curPoly.numVerts != vertsPerPrim) { System.out.printf("Surface %s: Unequal number of vertices ", curSurf.name); System.out.printf( "\n First prim had %d Cur Prim has %d\n", curPoly.numVerts, vertsPerPrim); return; } curPoly = curPoly.next; } curSurf.numVerts = vertCount; float vertices[] = new float[vertCount * 3]; int vInd = 0; float normals[] = new float[vertCount * 3]; int nInd = 0; curPoly = curSurf.polyHead; while (curPoly != null) { curVertLC = curPoly.vert; while (curVertLC != null) { // for(int i = 0; i < curPoly.numVerts; i++);{ VertCell curVert = vertArray.get(curVertLC.vert); vertices[vInd++] = (float) curVert.worldPos.x; vertices[vInd++] = (float) curVert.worldPos.y; vertices[vInd++] = (float) curVert.worldPos.z; normals[nInd++] = (float) vertNormArray[curVertLC.vert].x; normals[nInd++] = (float) vertNormArray[curVertLC.vert].y; normals[nInd++] = (float) vertNormArray[curVertLC.vert].z; curVertLC = curVertLC.next; } curPoly = curPoly.next; } // now put vertices and normals into VertexArray or Buffer curSurf.vertexBuffer = Buffers.newDirectFloatBuffer(vertices.length); curSurf.vertexBuffer.put(vertices); curSurf.vertexBuffer.rewind(); curSurf.normalBuffer = Buffers.newDirectFloatBuffer(normals.length); curSurf.normalBuffer.put(normals); curSurf.normalBuffer.rewind(); curSurf = curSurf.next; } }
/** Optional, throws GLException if not available in profile */ public final int gluScaleImage( int format, int widthin, int heightin, int typein, java.nio.Buffer datain, int widthout, int heightout, int typeout, java.nio.Buffer dataout) { validateMipmap(); java.nio.ByteBuffer in = null; java.nio.ByteBuffer out = null; in = copyToByteBuffer(datain); if (dataout instanceof java.nio.ByteBuffer) { out = (java.nio.ByteBuffer) dataout; } else if (dataout instanceof java.nio.ShortBuffer) { out = Buffers.newDirectByteBuffer(dataout.remaining() * Buffers.SIZEOF_SHORT); } else if (dataout instanceof java.nio.IntBuffer) { out = Buffers.newDirectByteBuffer(dataout.remaining() * Buffers.SIZEOF_INT); } else if (dataout instanceof java.nio.FloatBuffer) { out = Buffers.newDirectByteBuffer(dataout.remaining() * Buffers.SIZEOF_FLOAT); } else { throw new IllegalArgumentException( "Unsupported destination buffer type (must be byte, short, int, or float)"); } int errno = Mipmap.gluScaleImage( getCurrentGL2ES1(), format, widthin, heightin, typein, in, widthout, heightout, typeout, out); if (errno == 0) { out.rewind(); if (out != dataout) { if (dataout instanceof java.nio.ShortBuffer) { ((java.nio.ShortBuffer) dataout).put(out.asShortBuffer()); } else if (dataout instanceof java.nio.IntBuffer) { ((java.nio.IntBuffer) dataout).put(out.asIntBuffer()); } else if (dataout instanceof java.nio.FloatBuffer) { ((java.nio.FloatBuffer) dataout).put(out.asFloatBuffer()); } else { throw new RuntimeException("Should not reach here"); } } } return (errno); }
public static long EGLConfigId2EGLConfig(long display, int configID) { final IntBuffer attrs = Buffers.newDirectIntBuffer(new int[] {EGL.EGL_CONFIG_ID, configID, EGL.EGL_NONE}); final PointerBuffer configs = PointerBuffer.allocateDirect(1); final IntBuffer numConfigs = Buffers.newDirectIntBuffer(1); if (!EGL.eglChooseConfig(display, attrs, configs, 1, numConfigs)) { return 0; } if (numConfigs.get(0) == 0) { return 0; } return configs.get(0); }
private static boolean initByteOrder() { ByteBuffer tst_b = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT); // 32bit in native order IntBuffer tst_i = tst_b.asIntBuffer(); ShortBuffer tst_s = tst_b.asShortBuffer(); tst_i.put(0, 0x0A0B0C0D); return 0x0C0D == tst_s.get(0); }
private static List<GLCapabilitiesImmutable> getAvailableEGLConfigs( EGLGraphicsDevice eglDisplay, GLCapabilitiesImmutable caps) { final IntBuffer numConfigs = Buffers.newDirectIntBuffer(1); if (!EGL.eglGetConfigs(eglDisplay.getHandle(), null, 0, numConfigs)) { throw new GLException( "EGLDrawableFactory.getAvailableEGLConfigs: Get maxConfigs (eglGetConfigs) call failed, error " + EGLContext.toHexString(EGL.eglGetError())); } if (0 < numConfigs.get(0)) { final PointerBuffer configs = PointerBuffer.allocateDirect(numConfigs.get(0)); final IntBuffer attrs = EGLGraphicsConfiguration.GLCapabilities2AttribList(caps); final int winattrmask = GLGraphicsConfigurationUtil.getExclusiveWinAttributeBits(caps); if (EGL.eglChooseConfig( eglDisplay.getHandle(), attrs, configs, configs.capacity(), numConfigs) && numConfigs.get(0) > 0) { return EGLGraphicsConfigurationFactory.eglConfigs2GLCaps( eglDisplay, caps.getGLProfile(), configs, numConfigs.get(0), winattrmask, false /* forceTransparentFlag */); } } return new ArrayList<GLCapabilitiesImmutable>(0); }
public static void shaderSource(final GL _gl, final int shader, final CharSequence[] source) { final GL2ES2 gl = _gl.getGL2ES2(); if (!isShaderCompilerAvailable(_gl)) { throw new GLException("No compiler is available"); } final int count = (null != source) ? source.length : 0; if (count == 0) { throw new GLException("No sources specified"); } final IntBuffer lengths = Buffers.newDirectIntBuffer(count); for (int i = 0; i < count; i++) { lengths.put(i, source[i].length()); } if (source instanceof String[]) { // rare case .. gl.glShaderSource(shader, count, (String[]) source, lengths); } else { final String[] tmp = new String[source.length]; for (int i = source.length - 1; i >= 0; i--) { final CharSequence csq = source[i]; if (csq instanceof String) { // if ShaderCode.create(.. mutableStringBuilder == false ) tmp[i] = (String) csq; } else { // if ShaderCode.create(.. mutableStringBuilder == true ) tmp[i] = source[i].toString(); } } gl.glShaderSource(shader, count, tmp, lengths); } }
protected void loadData(String s) { try { double[] doubles = parseDoubles(s); if (doubles.length != width * height) { throw new IOException( "File doesn't contain width x height (" + (width * height) + ") values"); } DoubleBuffer buffer = Buffers.newDirectDoubleBuffer(width * height); buffer.put(doubles); buffer.rewind(); for (int i = 0; i < width * height; i++) { double elev = buffer.get(); minElevation = Math.min(minElevation, elev); maxElevation = Math.max(maxElevation, elev); } synchronized (elevationLock) { this.elevations = buffer; } // force a recalculate lastGlobe = null; firePropertyChange(AVKey.LAYER, null, this); } catch (IOException e) { if (loadAttempts < MAX_DOWNLOAD_ATTEMPTS) { loaded = false; Downloader.removeCache(url); Logging.logger().warning("Deleted corrupt cached data file for " + url); } else { e.printStackTrace(); } } }
public static BufferedImage convertImageToRGB( CLParams clParams, float[] sphericalImageFloats, int width, int height, ConversionType inputType) { FloatBuffer fb = Buffers.newDirectFloatBuffer(sphericalImageFloats); CLBuffer<FloatBuffer> sphericalImageBuffer = clParams.getContext().createBuffer(fb, CLBuffer.Mem.READ_WRITE); out.println("Transforming image to rgb coords"); CLKernel kernel = clParams.getKernel("convert_" + typeToString(inputType) + "_to_rgb"); kernel.putArg(sphericalImageBuffer).putArg(width).putArg(height).rewind(); long time = nanoTime(); clParams.getQueue().putWriteBuffer(sphericalImageBuffer, false); clParams.getQueue().put2DRangeKernel(kernel, 0, 0, width, height, 0, 0); clParams.getQueue().putReadBuffer(sphericalImageBuffer, true); time = nanoTime() - time; out.println("computation took: " + (time / 1000000) + "ms"); BufferedImage rgbImage = ImageUtils.createImage(width, height, sphericalImageBuffer, BufferedImage.TYPE_INT_RGB); return rgbImage; }
public static CLBuffer<FloatBuffer> convertRgbTo( CLParams clParams, BufferedImage image, ConversionType type) { out.println("Transforming image to spherical coords"); int width = image.getWidth(); int height = image.getHeight(); float[] pixels = image.getRaster().getPixels(0, 0, width, height, (float[]) null); // copy to direct float buffer FloatBuffer fb = Buffers.newDirectFloatBuffer(pixels); // allocate a OpenCL buffer using the direct fb as working copy CLBuffer<FloatBuffer> buffer = clParams.getContext().createBuffer(fb, CLBuffer.Mem.READ_WRITE); CLKernel kernel = clParams.getKernel("convert_rgb_to_" + typeToString(type)); kernel.putArg(buffer).putArg(image.getWidth()).putArg(image.getHeight()).rewind(); long time = nanoTime(); clParams.getQueue().putWriteBuffer(buffer, false); clParams.getQueue().put2DRangeKernel(kernel, 0, 0, image.getWidth(), image.getHeight(), 0, 0); clParams.getQueue().putReadBuffer(buffer, true); time = nanoTime() - time; out.println("computation took: " + (time / 1000000) + "ms"); return buffer; }
/** * Initialization method for any shader. Compiles and checks code. * * @param gl The global openGL instance. * @throws CompilationFailedException If the compilation of the GLSL code generated any errors. */ public void init(GL3 gl) throws CompilationFailedException { try { // First, give the source to OpenGL and compile gl.glShaderSource(getShaderPointer(), 1, source, (int[]) null, 0); gl.glCompileShader(getShaderPointer()); // Receive compilation status IntBuffer buf = Buffers.newDirectIntBuffer(1); gl.glGetShaderiv(getShaderPointer(), GL3.GL_COMPILE_STATUS, buf); int status = buf.get(0); // Check the status if (status == GL3.GL_FALSE) { // Prepare for additional information gl.glGetShaderiv(getShaderPointer(), GL3.GL_INFO_LOG_LENGTH, buf); int logLength = buf.get(0); byte[] reason = new byte[logLength]; // Get additional information gl.glGetShaderInfoLog(getShaderPointer(), logLength, null, 0, reason, 0); throw new CompilationFailedException( "Compilation of " + filename + " failed, " + new String(reason)); } } catch (UninitializedException e) { logger.error(e.getMessage()); } }
private final ByteBuffer copyToByteBuffer(Buffer buf) { if (buf instanceof ByteBuffer) { if (buf.position() == 0) { return (ByteBuffer) buf; } return Buffers.copyByteBuffer((ByteBuffer) buf); } else if (buf instanceof ShortBuffer) { return Buffers.copyShortBufferAsByteBuffer((ShortBuffer) buf); } else if (buf instanceof IntBuffer) { return Buffers.copyIntBufferAsByteBuffer((IntBuffer) buf); } else if (buf instanceof FloatBuffer) { return Buffers.copyFloatBufferAsByteBuffer((FloatBuffer) buf); } else { throw new IllegalArgumentException( "Unsupported buffer type (must be one of byte, short, int, or float)"); } }
private static final void resetGammaRamp( final long display, final int screenIdx, final Buffer originalGammaRamp) { final ShortBuffer rampData = (ShortBuffer) originalGammaRamp; final int capacity = rampData.capacity(); if ((capacity % 3) != 0) { throw new IllegalArgumentException("Must not be the original gamma ramp"); } final int size = capacity / 3; final ShortBuffer redRampData = Buffers.slice(rampData, 0 * size, size); final ShortBuffer greenRampData = Buffers.slice(rampData, 1 * size, size); final ShortBuffer blueRampData = Buffers.slice(rampData, 2 * size, size); if (DEBUG) { dumpRamp("RESET", size, redRampData, greenRampData, blueRampData); } X11Lib.XF86VidModeSetGammaRamp( display, screenIdx, size, redRampData, greenRampData, blueRampData); }
@Override public final ColorSpace allocate( int width, int height, ColorSpace sourceCM, int sourceComponents) throws RuntimeException { this.width = width; this.height = height; this.sourceComponents = sourceComponents; this.sourceCS = sourceCM; this.data = Buffers.newDirectByteBuffer(width * height * storageComponents); return storageCS; }
public OpenALAudioDevice( OpenALAudio audio, int sampleRate, boolean isMono, int bufferSize, int bufferCount) { this.audio = audio; channels = isMono ? 1 : 2; this.bufferSize = bufferSize; this.bufferCount = bufferCount; this.format = channels > 1 ? ALConstants.AL_FORMAT_STEREO16 : ALConstants.AL_FORMAT_MONO16; this.sampleRate = sampleRate; secondsPerBuffer = (float) bufferSize / bytesPerSample / channels / sampleRate; tempBuffer = Buffers.newDirectByteBuffer(bufferSize); }
protected static X11ExternalGLXContext create(GLDrawableFactory factory, GLProfile glp) { long ctx = GLX.glXGetCurrentContext(); if (ctx == 0) { throw new GLException("Error: current context null"); } long display = GLX.glXGetCurrentDisplay(); if (display == 0) { throw new GLException("Error: current display null"); } long drawable = GLX.glXGetCurrentDrawable(); if (drawable == 0) { throw new GLException( "Error: attempted to make an external GLDrawable without a drawable/context current"); } IntBuffer val = Buffers.newDirectIntBuffer(1); int w, h; GLX.glXQueryDrawable(display, drawable, GLX.GLX_WIDTH, val); w = val.get(0); GLX.glXQueryDrawable(display, drawable, GLX.GLX_HEIGHT, val); h = val.get(0); GLX.glXQueryContext(display, ctx, GLX.GLX_SCREEN, val); X11GraphicsScreen x11Screen = (X11GraphicsScreen) X11GraphicsScreen.createScreenDevice(display, val.get(0), false); GLX.glXQueryContext(display, ctx, GLX.GLX_FBCONFIG_ID, val); X11GLXGraphicsConfiguration cfg = null; // sometimes glXQueryContext on an external context gives us a framebuffer config ID // of 0, which doesn't work in a subsequent call to glXChooseFBConfig; if this happens, // create and use a default config (this has been observed when running on CentOS 5.5 inside // of VMWare Server 2.0 with the Mesa 6.5.1 drivers) if (VisualIDHolder.VID_UNDEFINED == val.get(0) || !X11GLXGraphicsConfiguration.GLXFBConfigIDValid( display, x11Screen.getIndex(), val.get(0))) { GLCapabilities glcapsDefault = new GLCapabilities(GLProfile.getDefault()); cfg = X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( glcapsDefault, glcapsDefault, null, x11Screen, VisualIDHolder.VID_UNDEFINED); if (DEBUG) { System.err.println( "X11ExternalGLXContext invalid FBCONFIG_ID " + val.get(0) + ", using default cfg: " + cfg); } } else { cfg = X11GLXGraphicsConfiguration.create(glp, x11Screen, val.get(0)); } final WrappedSurface ns = new WrappedSurface(cfg, drawable, w, h, true); return new X11ExternalGLXContext(new Drawable(factory, ns), ctx); }
public void updateVisibleOctant(GL2 gl) { if (leavesCount > 0) { // Limits refreshLimits(); // Switch to OpenGL2 select mode int capacity = 1 * 4 * leavesCount; // Each object take in maximium : 4 * name stack depth IntBuffer hitsBuffer = Buffers.newDirectIntBuffer(capacity); gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer); gl.glRenderMode(GL2.GL_SELECT); gl.glInitNames(); gl.glPushName(0); gl.glDisable(GL2.GL_CULL_FACE); // Disable flags // Draw the nodes cube in the select buffer for (Octant n : leaves) { if (n != null) { gl.glLoadName(n.leafId); n.displayOctant(gl); n.visible = false; } } visibleLeaves = 0; int nbRecords = gl.glRenderMode(GL2.GL_RENDER); if (vizController.getVizModel().isCulling()) { gl.glEnable(GL2.GL_CULL_FACE); gl.glCullFace(GL2.GL_BACK); } // Get the hits and add the nodes' objects to the array int depth = Integer.MAX_VALUE; int minDepth = -1; for (int i = 0; i < nbRecords; i++) { int hit = hitsBuffer.get(i * 4 + 3); // -1 Because of the glPushName(0) int minZ = hitsBuffer.get(i * 4 + 1); if (minZ < depth) { depth = minZ; minDepth = hit; } Octant nodeHit = leaves[hit]; nodeHit.visible = true; visibleLeaves++; } if (minDepth != -1) { Octant closestOctant = leaves[minDepth]; Vec3f pos = new Vec3f(closestOctant.getPosX(), closestOctant.getPosY(), closestOctant.getPosZ()); limits.setClosestPoint(pos); } } }
static long createBGRA8888Icon0( final Buffer pixels, final int width, final int height, final boolean isCursor, final int hotX, final int hotY) { if (null == pixels) { throw new IllegalArgumentException("data buffer/size"); } final boolean pixels_is_direct = Buffers.isDirect(pixels); return createBGRA8888Icon0( pixels_is_direct ? pixels : Buffers.getArray(pixels), pixels_is_direct ? Buffers.getDirectBufferByteOffset(pixels) : Buffers.getIndirectBufferByteOffset(pixels), pixels_is_direct, width, height, isCursor, hotX, hotY); }
public void writeSamples(byte[] data, int offset, int length) { if (length < 0) throw new IllegalArgumentException("length cannot be < 0."); if (sourceID == -1) { sourceID = audio.obtainSource(true); if (sourceID == -1) return; if (buffers == null) { buffers = Buffers.newDirectIntBuffer(bufferCount); audio.getAL().alGenBuffers(buffers.limit(), buffers); if (audio.getAL().alGetError() != ALConstants.AL_NO_ERROR) throw new GdxRuntimeException("Unabe to allocate audio buffers."); } audio.getAL().alSourcei(sourceID, ALConstants.AL_LOOPING, ALConstants.AL_FALSE); audio.getAL().alSourcef(sourceID, ALConstants.AL_GAIN, volume); // Fill initial buffers. int queuedBuffers = 0; for (int i = 0; i < bufferCount; i++) { int bufferID = buffers.get(i); int written = Math.min(bufferSize, length); tempBuffer.clear(); tempBuffer.put(data, offset, written).flip(); audio .getAL() .alBufferData(bufferID, format, tempBuffer, tempBuffer.remaining(), sampleRate); ib.put(0, bufferID).rewind(); audio.getAL().alSourceQueueBuffers(sourceID, ib.limit(), ib); length -= written; offset += written; queuedBuffers++; } // Queue rest of buffers, empty. tempBuffer.clear().flip(); for (int i = queuedBuffers; i < bufferCount; i++) { int bufferID = buffers.get(i); audio .getAL() .alBufferData(bufferID, format, tempBuffer, tempBuffer.remaining(), sampleRate); audio.getAL().alSourceQueueBuffers(sourceID, ib.limit(), ib); } audio.getAL().alSourcePlay(sourceID); isPlaying = true; } while (length > 0) { int written = fillBuffer(data, offset, length); length -= written; offset += written; } }
protected static IntBuffer generateTriStripIndices(int width, int height, boolean wrapWidth) { int w = width - 1; if (!wrapWidth) { width--; } height--; int indexCount = 2 * width * height + 4 * width - 2; IntBuffer buffer = Buffers.newDirectIntBuffer(indexCount); int k = 0; for (int i = 0; i < width; i++) { buffer.put(k); if (i > 0) { buffer.put(++k); buffer.put(k); } if (i % 2 == 0) // even { buffer.put(++k); for (int j = 0; j < height; j++) { k += w; buffer.put(k); buffer.put(++k); } } else // odd { buffer.put(--k); for (int j = 0; j < height; j++) { k -= w; buffer.put(k); buffer.put(--k); } } } if (wrapWidth) { boolean even = width % 2 == 0; int fixLast = 2 * height + 3 - (even ? 0 : 1); for (int i = indexCount - fixLast + 1; i < indexCount; i += 2) { buffer.put(i, buffer.get(i) - width); } if (even) { buffer.put(fixLast, buffer.get(fixLast) - width); } } return buffer; }
@Test public void bufferWithHostPointerTest() { out.println(" - - - highLevelTest; host pointer test - - - "); final int elements = NUM_ELEMENTS; final CLContext context = CLContext.create(); final ByteBuffer buffer = Buffers.newDirectByteBuffer(elements * SIZEOF_INT); // fill only first read buffer -> we will copy the payload to the second later. fillBuffer(buffer, 12345); final CLCommandQueue queue = context.getDevices()[0].createCommandQueue(); final Mem[] bufferConfig = new Mem[] {Mem.COPY_BUFFER, Mem.USE_BUFFER}; for (int i = 0; i < bufferConfig.length; i++) { out.println("testing with " + bufferConfig[i] + " config"); final CLBuffer<ByteBuffer> clBufferA = context.createBuffer(buffer, Mem.READ_ONLY, bufferConfig[i]); final CLBuffer<ByteBuffer> clBufferB = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY); // asynchronous write of data to GPU device, blocking read later to get the computed results // back. queue .putCopyBuffer(clBufferA, clBufferB, clBufferA.buffer.capacity()) // copy A -> B .putReadBuffer(clBufferB, true) // read B .finish(); assertEquals(2, context.getMemoryObjects().size()); clBufferA.release(); assertEquals(1, context.getMemoryObjects().size()); clBufferB.release(); assertEquals(0, context.getMemoryObjects().size()); // uploading worked when a==b. out.println("validating computed results..."); checkIfEqual(clBufferA.buffer, clBufferB.buffer, elements); out.println("results are valid"); } context.release(); }
private int checkSelection(GL2ES2 gl, int x, int y, int width, int height) { gl.glPixelStorei(GL2ES2.GL_PACK_ALIGNMENT, 4); gl.glPixelStorei(GL2ES2.GL_UNPACK_ALIGNMENT, 4); gl.glClearColor(sceneClearColor[0], sceneClearColor[1], sceneClearColor[2], sceneClearColor[3]); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); render(gl, width, height, 0, null, true); ByteBuffer pixel = Buffers.newDirectByteBuffer(4); pixel.order(ByteOrder.nativeOrder()); IntBuffer viewport = IntBuffer.allocate(4); gl.glGetIntegerv(GL2ES2.GL_VIEWPORT, viewport); gl.glReadPixels(x, viewport.get(3) - y, 1, 1, GL2ES2.GL_RGBA, GL2ES2.GL_UNSIGNED_BYTE, pixel); int qp = pixel.get(0) & 0xFF; int index = Math.round(((qp / 255.0f) * (count + 2)) - 1); if (index < 0 || index >= count) return -1; return index; }
public static IntBuffer CreatePBufferSurfaceAttribList(int width, int height, int texFormat) { IntBuffer attrs = Buffers.newDirectIntBuffer(16); int idx = 0; attrs.put(idx++, EGL.EGL_WIDTH); attrs.put(idx++, width); attrs.put(idx++, EGL.EGL_HEIGHT); attrs.put(idx++, height); attrs.put(idx++, EGL.EGL_TEXTURE_FORMAT); attrs.put(idx++, texFormat); attrs.put(idx++, EGL.EGL_TEXTURE_TARGET); attrs.put(idx++, EGL.EGL_NO_TEXTURE == texFormat ? EGL.EGL_NO_TEXTURE : EGL.EGL_TEXTURE_2D); attrs.put(idx++, EGL.EGL_NONE); return attrs; }
static int EGLConfigDrawableTypeBits(final EGLGraphicsDevice device, final long config) { int val = 0; final IntBuffer stype = Buffers.newDirectIntBuffer(1); if (!EGL.eglGetConfigAttrib(device.getHandle(), config, EGL.EGL_SURFACE_TYPE, stype)) { throw new GLException("Could not determine EGL_SURFACE_TYPE"); } final int _stype = stype.get(0); if (0 != (_stype & EGL.EGL_WINDOW_BIT)) { val |= GLGraphicsConfigurationUtil.WINDOW_BIT; } if (0 != (_stype & EGL.EGL_PIXMAP_BIT)) { val |= GLGraphicsConfigurationUtil.BITMAP_BIT; } if (0 != (_stype & EGL.EGL_PBUFFER_BIT)) { val |= GLGraphicsConfigurationUtil.PBUFFER_BIT | GLGraphicsConfigurationUtil.FBO_BIT; } return val; }
/** * Entry point to C language function: <code> * GLint {@native gluScaleImage}(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut) * </code> <br> * Part of <code>GLU_VERSION_1_X</code><br> * * @param dataIn a direct or array-backed {@link java.nio.Buffer} * @param dataOut a direct or array-backed {@link java.nio.Buffer} */ private int gluScaleImageC( int format, int wIn, int hIn, int typeIn, Buffer dataIn, int wOut, int hOut, int typeOut, Buffer dataOut) { final boolean dataIn_is_direct = Buffers.isDirect(dataIn); final boolean dataOut_is_direct = Buffers.isDirect(dataOut); final long __addr_ = getGLUProcAddressTable()._addressof_gluScaleImage; if (__addr_ == 0) { throw new GLException(String.format("Method \"%s\" not available", "gluScaleImage")); } return dispatch_gluScaleImageC1( format, wIn, hIn, typeIn, dataIn_is_direct ? dataIn : Buffers.getArray(dataIn), dataIn_is_direct ? Buffers.getDirectBufferByteOffset(dataIn) : Buffers.getIndirectBufferByteOffset(dataIn), dataIn_is_direct, wOut, hOut, typeOut, dataOut_is_direct ? dataOut : Buffers.getArray(dataOut), dataOut_is_direct ? Buffers.getDirectBufferByteOffset(dataOut) : Buffers.getIndirectBufferByteOffset(dataOut), dataOut_is_direct, __addr_); }
public static boolean isEGLConfigValid(long display, long config) { if (0 == config) { return false; } final IntBuffer val = Buffers.newDirectIntBuffer(1); // get the configID if (!EGL.eglGetConfigAttrib(display, config, EGL.EGL_CONFIG_ID, val)) { final int eglErr = EGL.eglGetError(); if (DEBUG) { System.err.println( dbgCfgFailIntro + "EGL_CONFIG_ID" + dbgCfgFailForConfig + toHexString(config) + dbgCfgFailError + toHexString(eglErr)); } return false; } return true; }