Java Code Examples for java.nio.IntBuffer#flip()
The following examples show how to use
java.nio.IntBuffer#flip() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IconBatcher.java From constellation with Apache License 2.0 | 6 votes |
@Override public GLRenderableUpdateTask createBatch(final VisualAccess access) { final int numVertices = access.getVertexCount(); final FloatBuffer colorBuffer = Buffers.newDirectFloatBuffer(COLOR_BUFFER_WIDTH * numVertices); final IntBuffer iconBuffer = Buffers.newDirectIntBuffer(ICON_BUFFER_WIDTH * numVertices); for (int pos = 0; pos < numVertices; pos++) { bufferColorInfo(pos, colorBuffer, access); bufferIconInfo(pos, iconBuffer, access); } colorBuffer.flip(); iconBuffer.flip(); return gl -> { if (numVertices > 0) { batch.initialise(numVertices); batch.buffer(gl, colorTarget, colorBuffer); batch.buffer(gl, iconTarget, iconBuffer); batch.finalise(gl); } }; }
Example 2
Source File: Textures.java From Visage with MIT License | 6 votes |
public static void upload(BufferedImage img, int format, int tex) { int width = img.getWidth(); int height = img.getHeight(); if (Visage.trace) Visage.log.finest("Uploading "+width+"x"+height+" ("+(width*height)+" pixel) image"); BufferedImage unindexed = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); int[] argb = new int[width*height]; img.getRGB(0, 0, width, height, argb, 0, width); unindexed.setRGB(0, 0, width, height, argb, 0, width); unindexed.coerceData(true); unindexed.getRGB(0, 0, width, height, argb, 0, width); IntBuffer buf = BufferUtils.createIntBuffer(width*height); buf.put(argb); buf.flip(); glBindTexture(GL_TEXTURE_2D, tex); glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, buf); checkGLError(); }
Example 3
Source File: IntBufferDemo01.java From javacore with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
public static void main(String[] args) { IntBuffer buf = IntBuffer.allocate(10); // 准备出10个大小的缓冲区 System.out.print("1、写入数据之前的position、limit和capacity:"); System.out.println("position = " + buf.position() + ",limit = " + buf.limit() + ",capacty = " + buf.capacity()); int[] temp = { 5, 7, 9 };// 定义一个int数组 buf.put(3); // 设置一个数据 buf.put(temp); // 此时已经存放了四个记录 System.out.print("2、写入数据之后的position、limit和capacity:"); System.out.println("position = " + buf.position() + ",limit = " + buf.limit() + ",capacty = " + buf.capacity()); buf.flip(); // 重设缓冲区 // postion = 0 ,limit = 原本position System.out.print("3、准备输出数据时的position、limit和capacity:"); System.out.println("position = " + buf.position() + ",limit = " + buf.limit() + ",capacty = " + buf.capacity()); System.out.print("缓冲区中的内容:"); while (buf.hasRemaining()) { int x = buf.get(); System.out.print(x + "、"); } }
Example 4
Source File: GLUtils.java From trekarta with GNU General Public License v3.0 | 5 votes |
/** * Specifies a list of color buffers to be drawn into. * * @param num Specifies the number of buffers in bufs. * @param glEnum Points to an array of symbolic constants specifying the buffers into which fragment colors or data values will be written. */ public static void glDrawBuffers(int num, int[] glEnum) { IntBuffer buf = MapRenderer.getIntBuffer(num); buf.put(glEnum, 0, num); buf.flip(); gl30.drawBuffers(num, buf); }
Example 5
Source File: FBOGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.Graphics#destroy() */ public void destroy() { super.destroy(); IntBuffer buffer = BufferUtils.createIntBuffer(1); buffer.put(FBO); buffer.flip(); EXTFramebufferObject.glDeleteFramebuffersEXT(buffer); valid = false; }
Example 6
Source File: Shader.java From Ultraino with MIT License | 5 votes |
int initShader(GL2 gl, int nShaderType, String source) { int shader = gl.glCreateShader(nShaderType); if (shader != 0) { String[] sources = new String[]{ source }; gl.glShaderSource(shader, 1, sources, null); gl.glCompileShader(shader); IntBuffer compiled = BufferUtils.createIntBuffer(1); gl.glGetShaderiv(shader, GL2.GL_COMPILE_STATUS, compiled); if (compiled.get() == 0) { IntBuffer infoLen = BufferUtils.createIntBuffer(1); gl.glGetShaderiv(shader, GL2.GL_INFO_LOG_LENGTH, infoLen); int length = infoLen.get(); if (length > 0) { ByteBuffer buf = BufferUtils.createByteBuffer(length); infoLen.flip(); gl.glGetShaderInfoLog(shader, length, infoLen, buf); byte[] b = new byte[infoLen.get()]; buf.get(b); System.out.println("Prgram : " + fProgram); System.out.println(source); System.err.println("Error compiling shader " + vProgram + " " + fProgram + " -> " + new String(b)); } } } return shader; }
Example 7
Source File: BufferTest.java From JavaBase with MIT License | 5 votes |
/** * flip 方法直译就是翻转的意思, 也就是说在读写之间切换, 做好准备工作 */ @Test public void testFlip() { IntBuffer buffer = IntBuffer.allocate(1024); buffer.put(1); // 需要使用flip方法来进行模式的切换, 如果没有做读写操作就直接调用就会抛出 BufferOverflowException 异常 // 也就是说, 在写和读操作后, 需要调用该方法才能进行下一步的写和读 buffer.flip(); buffer.put(2); buffer.flip(); int result = buffer.get(); log.info("result={}", result); }
Example 8
Source File: BufferUtil.java From Lwjgl3-Game-Engine-Programming-Series with MIT License | 5 votes |
public static IntBuffer createFlippedBuffer(int... values) { IntBuffer buffer = createIntBuffer(values.length); buffer.put(values); buffer.flip(); return buffer; }
Example 9
Source File: IntBufferDemo.java From LearningOfThinkInJava with Apache License 2.0 | 5 votes |
public static void main(String[] args) { ByteBuffer bb=ByteBuffer.allocate(BSIZE); IntBuffer ib=bb.asIntBuffer(); ib.put(new int[]{11,42,47,99,143,811,1016}); System.out.println(ib.getClass().getName()); System.out.println(ib.get(3)); ib.put(3,1811); ib.flip(); while (ib.hasRemaining()){ int i=ib.get(); System.out.println(i); } }
Example 10
Source File: Util.java From 3DGameEngine with Apache License 2.0 | 5 votes |
public static IntBuffer CreateFlippedBuffer(int... values) { IntBuffer buffer = CreateIntBuffer(values.length); buffer.put(values); buffer.flip(); return buffer; }
Example 11
Source File: TransparencyFbo.java From oreon-engine with GNU General Public License v3.0 | 5 votes |
public TransparencyFbo(int width, int height) { GLTexture albedoAttachment = new TextureImage2D(width, height, ImageFormat.RGBA16FLOAT, SamplerFilter.Nearest); GLTexture alphaAttachment = new TextureImage2D(width, height, ImageFormat.RGBA16FLOAT, SamplerFilter.Nearest); GLTexture lightScatteringAttachment = new TextureImage2D(width, height, ImageFormat.RGBA16FLOAT, SamplerFilter.Nearest); GLTexture depthAttachment = new TextureImage2D(width, height, ImageFormat.DEPTH32FLOAT, SamplerFilter.Nearest); attachments.put(Attachment.COLOR, albedoAttachment); attachments.put(Attachment.ALPHA, alphaAttachment); attachments.put(Attachment.LIGHT_SCATTERING, lightScatteringAttachment); attachments.put(Attachment.DEPTH, depthAttachment); IntBuffer drawBuffers = BufferUtil.createIntBuffer(3); drawBuffers.put(GL_COLOR_ATTACHMENT0); drawBuffers.put(GL_COLOR_ATTACHMENT1); drawBuffers.put(GL_COLOR_ATTACHMENT2); drawBuffers.flip(); frameBuffer = new GLFramebuffer(); frameBuffer.bind(); frameBuffer.createColorTextureAttachment(albedoAttachment.getHandle(),0); frameBuffer.createColorTextureAttachment(alphaAttachment.getHandle(),1); frameBuffer.createColorTextureAttachment(lightScatteringAttachment.getHandle(),2); frameBuffer.createDepthTextureAttachment(depthAttachment.getHandle()); frameBuffer.setDrawBuffers(drawBuffers); frameBuffer.checkStatus(); frameBuffer.unbind(); }
Example 12
Source File: KeyEventSupport.java From termd with Apache License 2.0 | 5 votes |
@Override public IntBuffer buffer() { int length = length(); IntBuffer buf = IntBuffer.allocate(length); for (int i = 0; i < length; i++) { buf.put(getCodePointAt(i)); } buf.flip(); return buf; }
Example 13
Source File: BufferUtil.java From oreon-engine with GNU General Public License v3.0 | 5 votes |
public static ByteBuffer createByteBuffer(int... values){ ByteBuffer byteBuffer = memAlloc(Integer.BYTES * values.length); IntBuffer intBuffer = byteBuffer.asIntBuffer(); intBuffer.put(values); intBuffer.flip(); return byteBuffer; }
Example 14
Source File: LineBatcher.java From constellation with Apache License 2.0 | 5 votes |
@Override public GLRenderableUpdateTask createBatch(final VisualAccess access) { int lineCounter = 0; for (int link = 0; link < access.getLinkCount(); link++) { if (access.getLinkSource(link) != access.getLinkDestination(link)) { connections.add(NEW_LINK); for (int pos = 0; pos < access.getLinkConnectionCount(link); pos++) { final int connection = access.getLinkConnection(link, pos); connectionPosToBufferPos.put(connection, lineCounter++); connections.add(connection); } } } final int numLines = lineCounter; FloatBuffer colorBuffer = Buffers.newDirectFloatBuffer(numLines * 2 * COLOR_BUFFER_WIDTH); IntBuffer dataBuffer = Buffers.newDirectIntBuffer(numLines * 2 * CONNECTION_INFO_BUFFER_WIDTH); connections.forEach(pos -> { if (pos == NEW_LINK) { leftOffset = 0; } else { bufferColorInfo(pos, colorBuffer, access); bufferConnectionInfo(pos, dataBuffer, access); } }); colorBuffer.flip(); dataBuffer.flip(); return gl -> { if (numLines > 0) { batch.initialise(numLines * 2); batch.buffer(gl, colorTarget, colorBuffer); batch.buffer(gl, connectionInfoTarget, dataBuffer); batch.finalise(gl); } }; }
Example 15
Source File: BufferUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Generate a new IntBuffer using the given array of ints. The IntBuffer * will be data.length long and contain the int data as data[0], data[1]... * etc. * * @param data * array of ints to place into a new IntBuffer * @return a new direct, flipped IntBuffer, or null if data was null */ public static IntBuffer createIntBuffer(int... data) { if (data == null) { return null; } IntBuffer buff = createIntBuffer(data.length); buff.clear(); buff.put(data); buff.flip(); return buff; }
Example 16
Source File: GLUtils.java From trekarta with GNU General Public License v3.0 | 4 votes |
public static void glDeleteTextures(int num, int[] ids) { IntBuffer buf = MapRenderer.getIntBuffer(num); buf.put(ids, 0, num); buf.flip(); gl.deleteTextures(num, buf); }
Example 17
Source File: Water.java From oreon-engine with GNU General Public License v3.0 | 4 votes |
public Water(int patches, GLShaderProgram shader, GLShaderProgram wireframeShader) { config = new WaterConfig(); config.loadFile("water-config.properties"); GLContext.getResources().setWaterConfig(config); GLPatchVBO meshBuffer = new GLPatchVBO(); meshBuffer.addData(MeshGenerator.generatePatch2D4x4(patches),16); renderConfig = new WaterRenderParameter(); GLRenderInfo renderInfo = new GLRenderInfo(shader, renderConfig, meshBuffer); GLRenderInfo wireframeRenderInfo = new GLRenderInfo(wireframeShader, renderConfig, meshBuffer); dudv = new TextureImage2D("textures/water/dudv/dudv1.jpg", SamplerFilter.Trilinear); addComponent(NodeComponentType.MAIN_RENDERINFO, renderInfo); addComponent(NodeComponentType.WIREFRAME_RENDERINFO, wireframeRenderInfo); fft = new FFT(config.getN(), config.getL(), config.getAmplitude(), config.getWindDirection(), config.getAlignment(), config.getWindSpeed(), config.getCapillarWavesSupression()); fft.setT_delta(config.getT_delta()); fft.setChoppy(config.isChoppy()); fft.init(); normalmapRenderer = new NormalRenderer(config.getN()); getNormalmapRenderer().setStrength(config.getNormalStrength()); reflection_texture = new TextureImage2D(BaseContext.getConfig().getFrameWidth()/2, BaseContext.getConfig().getFrameHeight()/2, ImageFormat.RGBA16FLOAT, SamplerFilter.Nearest); IntBuffer drawBuffers = BufferUtil.createIntBuffer(1); drawBuffers.put(GL_COLOR_ATTACHMENT0); drawBuffers.flip(); reflection_fbo = new GLFramebuffer(); reflection_fbo.bind(); reflection_fbo.createColorTextureAttachment(reflection_texture.getHandle(),0); reflection_fbo.createDepthBufferAttachment(BaseContext.getConfig().getFrameWidth()/2, BaseContext.getConfig().getFrameHeight()/2); reflection_fbo.setDrawBuffers(drawBuffers); reflection_fbo.checkStatus(); reflection_fbo.unbind(); refraction_texture = new TextureImage2D(BaseContext.getConfig().getFrameWidth()/2, BaseContext.getConfig().getFrameHeight()/2, ImageFormat.RGBA16FLOAT, SamplerFilter.Nearest); refraction_fbo = new GLFramebuffer(); refraction_fbo.bind(); refraction_fbo.createColorTextureAttachment(refraction_texture.getHandle(),0); refraction_fbo.createDepthBufferAttachment(BaseContext.getConfig().getFrameWidth()/2, BaseContext.getConfig().getFrameHeight()/2); refraction_fbo.setDrawBuffers(drawBuffers); refraction_fbo.checkStatus(); refraction_fbo.unbind(); refractionRenderList = new RenderList(); reflectionRenderList = new RenderList(); }
Example 18
Source File: GLUtils.java From trekarta with GNU General Public License v3.0 | 4 votes |
public static void glDeleteFrameBuffers(int num, int[] ids) { IntBuffer buf = MapRenderer.getIntBuffer(num); buf.put(ids, 0, num); buf.flip(); gl.deleteFramebuffers(num, buf); }
Example 19
Source File: BridgeTestCommand.java From commons-rng with Apache License 2.0 | 4 votes |
/** * Starts the executable process and writes {@code int} values to a data file and the stdin * of the executable. Captures stdout of the executable to a file. */ private void runBridgeTest() { final List<String> command = ProcessUtils.buildSubProcessCommand(executable, executableArguments); try { final File dataFile = new File(fileOutputPrefix + ".data"); final File outputFile = new File(fileOutputPrefix + ".out"); final File errorFile = new File(fileOutputPrefix + ".err"); // Store int values final IntBuffer buffer = IntBuffer.allocate(Integer.SIZE * 2); try (BufferedWriter textOutput = Files.newBufferedWriter(dataFile.toPath())) { // Write int data using a single bit in all possible positions int value = 1; for (int i = 0; i < Integer.SIZE; i++) { writeInt(textOutput, buffer, value); value <<= 1; } // Write random int data while (buffer.remaining() != 0) { writeInt(textOutput, buffer, ThreadLocalRandom.current().nextInt()); } } // Pass the same values to the output application buffer.flip(); UniformRandomProvider rng = new IntProvider() { @Override public int next() { return buffer.get(); } }; // Start the application. final ProcessBuilder builder = new ProcessBuilder(command); builder.redirectOutput(ProcessBuilder.Redirect.to(outputFile)); builder.redirectError(ProcessBuilder.Redirect.to(errorFile)); final Process testingProcess = builder.start(); // Open the stdin of the process and write to a custom data sink. // Note: The 'bridge' command only supports 32-bit data in order to // demonstrate passing suitable data for TestU01 BigCrush. final boolean raw64 = false; try (RngDataOutput sink = RNGUtils.createDataOutput(rng, raw64, testingProcess.getOutputStream(), buffer.capacity() * 4, byteOrder)) { sink.write(rng); } final Integer exitValue = ProcessUtils.getExitValue(testingProcess); if (exitValue == null) { LogUtils.error("%s did not exit. Process was killed.", command.get(0)); } else { if (exitValue.intValue() != 0) { LogUtils.error("%s exit code = %d", command.get(0), exitValue.intValue()); } } } catch (IOException ex) { throw new ApplicationException("Failed to run process: " + ex.getMessage(), ex); } }
Example 20
Source File: Vbo.java From OpenGL-Animation with The Unlicense | 4 votes |
public void storeData(int[] data){ IntBuffer buffer = BufferUtils.createIntBuffer(data.length); buffer.put(data); buffer.flip(); storeData(buffer); }