Java Code Examples for com.jogamp.opengl.GL4#glBindImageTexture()
The following examples show how to use
com.jogamp.opengl.GL4#glBindImageTexture() .
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: Gl_430_fbo_without_attachment.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindSampler(0, samplerName.get(0)); // Render gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.RENDER)); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl4.glBindImageTexture(Semantic.Image.DIFFUSE, textureName.get(Texture.COLORBUFFER), 0, false, 0, GL_WRITE_ONLY, GL_RGBA8); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); // Splash gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SPLASH)); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER)); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); return true; }
Example 2
Source File: Gl_430_image_sampling.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.glMapBufferRange( GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 1000.0f); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindImageTexture(0, textureName.get(0), 0, false, 0, GL_READ_ONLY, GL_RGBA8); gl4.glBindImageTexture(1, textureName.get(0), 1, false, 0, GL_READ_ONLY, GL_RGBA8); gl4.glBindImageTexture(2, textureName.get(0), 2, false, 0, GL_READ_ONLY, GL_RGBA8); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 3, 0, 0); return true; }
Example 3
Source File: Gl_430_image_store.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glDrawBuffer(GL_BACK); gl4.glClearBufferfv(GL_COLOR, 0, new float[]{0.0f, 0.5f, 1.0f, 1.0f}, 0); // Renderer to image { gl4.glDrawBuffer(GL_NONE); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SAVE)); gl4.glBindImageTexture(Semantic.Image.DIFFUSE, textureName.get(0), 0, false, 0, GL_WRITE_ONLY, GL_RGBA8); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); } // Read from image { gl4.glDrawBuffer(GL_BACK); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.READ)); gl4.glBindImageTexture(Semantic.Image.DIFFUSE, textureName.get(0), 0, false, 0, GL_READ_ONLY, GL_RGBA8); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); } return true; }
Example 4
Source File: Gl_420_image_store.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glDrawBuffer(GL_BACK); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0.5f).put(2, 1).put(3, 1)); // Renderer to image { gl4.glDrawBuffer(GL_NONE); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SAVE)); gl4.glBindImageTexture(Semantic.Image.DIFFUSE, textureName.get(0), 0, false, 0, GL_WRITE_ONLY, GL_RGBA8); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); } // Read from image { int border = 8; gl4.glEnable(GL_SCISSOR_TEST); gl4.glScissorIndexed(0, border, border, (windowSize.x - 2) * border, (windowSize.y - 2) * border); gl4.glDrawBuffer(GL_BACK); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.READ)); gl4.glBindImageTexture(Semantic.Image.DIFFUSE, textureName.get(0), 0, false, 0, GL_READ_ONLY, GL_RGBA8); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); gl4.glDisable(GL_SCISSOR_TEST); } return true; }
Example 5
Source File: Gl_430_program_compute_image.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.glMapBufferRange( GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspectiveFov_((float) Math.PI * 0.25f, windowSize.x, windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glBindProgramPipeline(pipelineName.get(Program.COMPUTE)); gl4.glBindImageTexture(Image.POSITION_INPUT, textureName.get(Texture.POSITION_INPUT), 0, false, 0, GL_READ_ONLY, GL_RGBA32F); gl4.glBindImageTexture(Image.TEXCOORD_INPUT, textureName.get(Texture.TEXCOORD_INPUT), 0, false, 0, GL_READ_ONLY, GL_RGBA32F); gl4.glBindImageTexture(Image.COLOR_INPUT, textureName.get(Texture.COLOR_INPUT), 0, false, 0, GL_READ_ONLY, GL_RGBA32F); gl4.glBindImageTexture(Image.POSITION_OUTPUT, textureName.get(Texture.POSITION_OUTPUT), 0, false, 0, GL_WRITE_ONLY, GL_RGBA32F); gl4.glBindImageTexture(Image.TEXCOORD_OUTPUT, textureName.get(Texture.TEXCOORD_OUTPUT), 0, false, 0, GL_WRITE_ONLY, GL_RGBA32F); gl4.glBindImageTexture(Image.COLOR_OUTPUT, textureName.get(Texture.COLOR_OUTPUT), 0, false, 0, GL_WRITE_ONLY, GL_RGBA32F); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glDispatchCompute(vertexCount, 1, 1); gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0); gl4.glBindProgramPipeline(pipelineName.get(Program.GRAPHICS)); gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Sampler.DIFFUSE); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Sampler.POSITION); gl4.glBindTexture(GL_TEXTURE_BUFFER, textureName.get(Texture.POSITION_OUTPUT)); gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Sampler.TEXCOORD); gl4.glBindTexture(GL_TEXTURE_BUFFER, textureName.get(Texture.TEXCOORD_OUTPUT)); gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Sampler.COLOR); gl4.glBindTexture(GL_TEXTURE_BUFFER, textureName.get(Texture.COLOR_OUTPUT)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); return true; }
Example 6
Source File: Gl_430_program_compute_variable_group_size.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.glMapBufferRange( GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspectiveFov_((float) Math.PI * 0.25f, windowSize.x, windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glBindProgramPipeline(pipelineName.get(Program.COMPUTE)); gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Image.DIFFUSE); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.INPUT)); gl4.glBindImageTexture(ImageUnit.OUTPUT, textureName.get(Texture.OUTPUT), 0, false, 0, GL_WRITE_ONLY, GL_RGBA8); Vec2i workGroupSize = new Vec2i(32); Vec2i ndRange = textureSize.div_(workGroupSize); gl4.glDispatchComputeGroupSizeARB( ndRange.x, ndRange.y, 1, // (8, 8, 1) workGroupSize.x, workGroupSize.y, 1); // (32, 32, 1) gl4.glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT); gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glClearBufferfv(GL_COLOR, 0, white); gl4.glBindProgramPipeline(pipelineName.get(Program.GRAPHICS)); gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Image.DIFFUSE); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.OUTPUT)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); return true; }
Example 7
Source File: Gl_500_shader_group_nv.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { ByteBuffer pointer = gl4.glMapNamedBufferRange(bufferName.get(Buffer.TRANSFORM), 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); // Make sure the uniform buffer is uploaded gl4.glUnmapNamedBuffer(bufferName.get(Buffer.TRANSFORM)); } gl4.glEnable(GL_DEPTH_TEST); gl4.glDepthFunc(GL_LESS); gl4.glClearTexImage(textureName.get(Texture.COLORBUFFER), 0, GL_RGBA, GL_UNSIGNED_BYTE, clearColorBuffer); gl4.glClearTexImage(textureName.get(Texture.RENDERBUFFER), 0, GL_DEPTH_COMPONENT, GL_FLOAT, clearRenderBuffer); gl4.glClearTexImage(textureName.get(Texture.INVOCATION_COUNT), 0, GL_RED_INTEGER, GL_UNSIGNED_INT, clearInvocationCount); gl4.glViewportIndexedf(0, 0, 0, windowSize.x * FRAMEBUFFER_SCALE, windowSize.y * FRAMEBUFFER_SCALE); gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.TEXTURE)); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.TEXTURE)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindImageTexture(0, textureName.get(Texture.INVOCATION_COUNT), 0, false, 0, GL_WRITE_ONLY, GL_R32UI); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 5, 0, 0); gl4.glDisable(GL_DEPTH_TEST); gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SPLASH)); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.SPLASH)); gl4.glBindImageTexture(0, textureName.get(Texture.INVOCATION_COUNT), 0, false, 0, GL_READ_ONLY, GL_R32UI); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); return true; }
Example 8
Source File: Gl_440_fbo_without_attachment.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName[Buffer.TRANSFORM]); ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspectiveFov_((float) Math.PI * 0.25f, windowSize.x, windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } // Render FloatBuffer clearBuffer = GLBuffers.newDirectFloatBuffer(new float[]{1.0f, 0.5f, 0.0f, 1.0f}); gl4.glClearTexImage(textureName[Texture.COLORBUFFER], 0, GL_RGBA, GL_FLOAT, clearBuffer); BufferUtils.destroyDirectBuffer(clearBuffer); gl4.glViewportIndexedf(0, 0, 0, windowSize.x * supersampling, windowSize.y * supersampling); gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName[0]); gl4.glBindSampler(0, samplerName[Pipeline.RENDER]); gl4.glBindVertexArray(vertexArrayName[Pipeline.RENDER]); gl4.glBindProgramPipeline(pipelineName[Pipeline.RENDER]); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName[Texture.DIFFUSE]); gl4.glBindImageTexture(Semantic.Image.DIFFUSE, textureName[Texture.COLORBUFFER], 0, false, 0, GL_WRITE_ONLY, GL_RGBA8); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName[Buffer.TRANSFORM]); gl4.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, Semantic.Storage.VERTEX, bufferName[Buffer.VERTEX]); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); // Splash gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl4.glBindSampler(0, samplerName[Pipeline.SPLASH]); gl4.glBindVertexArray(vertexArrayName[Pipeline.SPLASH]); gl4.glBindProgramPipeline(pipelineName[Pipeline.SPLASH]); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName[Texture.COLORBUFFER]); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); return true; }