Java Code Examples for com.jogamp.opengl.GL4#glBlitFramebuffer()
The following examples show how to use
com.jogamp.opengl.GL4#glBlitFramebuffer() .
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_direct_state_access_ext.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { ByteBuffer pointer = gl4.glMapNamedBufferRange(bufferName.get(Buffer.TRANSFORM), 0, uniformBlockSize, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, FRAMEBUFFER_SIZE.x / FRAMEBUFFER_SIZE.y, 0.1f, 100.0f); pointer.position(0); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(new Mat4(1)).toFa_()); // Make sure the uniform buffer is uploaded gl4.glUnmapNamedBuffer(bufferName.get(Buffer.TRANSFORM)); } gl4.glBindProgramPipeline(pipelineName.get(0)); // Step 1: render the scene in a multisampled framebuffer renderFBO(gl4); // Step 2: resolve MSAA gl4.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER)); gl4.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE)); gl4.glBlitFramebuffer( 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_COLOR_BUFFER_BIT, GL_NEAREST); // Step 3: Blit resolved colorbuffer. Resolve and blit can't be done in a single step gl4.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE)); gl4.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); gl4.glBlitFramebuffer( 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, 0, windowSize.x, windowSize.y, GL_COLOR_BUFFER_BIT, GL_NEAREST); return true; }
Example 2
Source File: Gl_400_fbo_multisample.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0); gl4.glUseProgram(programName); gl4.glUniform1i(uniformDiffuse, 0); // Pass 1, render the scene in a multisampled framebuffer gl4.glEnable(GL_MULTISAMPLE); gl4.glEnable(GL_SAMPLE_SHADING); gl4.glMinSampleShading(4 / 2.0f); float[] min = {0}; gl4.glGetFloatv(GL_MIN_SAMPLE_SHADING_VALUE, min, 0); //glEnable(GL_SAMPLE_MASK); //glSampleMaski(0, 0xFF); renderFBO(gl4, framebufferName.get(Framebuffer.RENDER)); gl4.glDisable(GL_MULTISAMPLE); // Resolved multisampling gl4.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER)); gl4.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE)); gl4.glBlitFramebuffer( 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_COLOR_BUFFER_BIT, GL_NEAREST); gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); // Pass 2, render the colorbuffer from the multisampled framebuffer gl4.glViewport(0, 0, windowSize.x, windowSize.y); renderFB(gl4, textureName.get(Texture.COLOR)); return true; }
Example 3
Source File: Gl_430_fbo_invalidate.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); projection.mul(viewMat4()).mul(model).toDbb(pointer); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } ////////////////////////////// // Render multisampled texture gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.MULTISAMPLE)); gl4.glViewportIndexedf(0, 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1.0f).put(1, 0.5f).put(2, 0.0f).put(3, 1.0f)); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.MULTISAMPLE)); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.MULTISAMPLE)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glEnable(GL_MULTISAMPLE); { gl4.glDrawArraysInstancedBaseInstance(GL_LINE_LOOP, 0, vertexData.length / 2, 3, 0); } gl4.glDisable(GL_MULTISAMPLE); ////////////////////////// // Resolving multisampling gl4.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.MULTISAMPLE)); gl4.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferName.get(Framebuffer.COLOR)); gl4.glBlitFramebuffer( 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_COLOR_BUFFER_BIT, GL_NEAREST); int[] attachments = {GL_COLOR_ATTACHMENT0}; gl4.glInvalidateFramebuffer(GL_READ_FRAMEBUFFER, 1, attachments, 0); gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); ////////////////////////////////////// // Render resolved multisample texture gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); //glDisable(GL_MULTISAMPLE); gl4.glActiveTexture(GL_TEXTURE0); //glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, TextureName[texture::MULTISAMPLE]); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLOR)); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.SPLASH)); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SPLASH)); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 6, 1, 0); return true; }
Example 4
Source File: Gl_420_sampler_fetch.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; Vec2i framebufferSize = windowSize.mul_(FRAMEBUFFER_SCALE); { 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.perspective_((float) Math.PI * 0.25f, windowSize.x * 0.5f / windowSize.y, 0.1f, 1000.0f); Mat4 model = new Mat4(1.0f); projection.mul(viewMat4()).mul(model.scale(new Vec3(4.f))).toDbb(pointer); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl4.glViewportIndexedf(0, 0, 0, framebufferSize.x, framebufferSize.y); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0.5f).put(2, 0).put(3, 1)); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); gl4.glBindProgramPipeline(pipelineName.get(Program.PROG)); gl4.glViewportIndexedf(0, framebufferSize.x * 0.5f * 0.0f, 0, framebufferSize.x * 0.5f, framebufferSize.y); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); gl4.glBindProgramPipeline(pipelineName.get(Program.FUNC)); gl4.glViewportIndexedf(0, framebufferSize.x * 0.5f * 1.0f, 0, framebufferSize.x * 0.5f, framebufferSize.y); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); gl4.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(0)); gl4.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); gl4.glBlitFramebuffer( 0, 0, framebufferSize.x, framebufferSize.y, 0, 0, windowSize.x, windowSize.y, GL_COLOR_BUFFER_BIT, GL_NEAREST); return true; }
Example 5
Source File: Gl_420_primitive_line_aa.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); projection.mul(viewMat4()).mul(model).toDbb(pointer); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } ////////////////////////////// // Render multisampled texture //glBindFramebuffer(GL_FRAMEBUFFER, 0); gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.MULTISAMPLE)); //glEnable(GL_MULTISAMPLE); gl4.glViewportIndexedf(0, 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0.5f).put(2, 0).put(3, 1)); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.MULTISAMPLE)); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.MULTISAMPLE)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glDrawArraysInstancedBaseInstance(GL_LINE_LOOP, 0, vertexData.length, 3, 0); ////////////////////////// // Resolving multisampling gl4.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.MULTISAMPLE)); gl4.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferName.get(Framebuffer.COLOR)); gl4.glBlitFramebuffer( 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_COLOR_BUFFER_BIT, GL_NEAREST); gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); ////////////////////////////////////// // Render resolved multisample texture gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); //glDisable(GL_MULTISAMPLE); gl4.glActiveTexture(GL_TEXTURE0); //glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, TextureName[texture::MULTISAMPLE]); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLOR)); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.SPLASH)); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SPLASH)); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 6, 1, 0); return true; }