Java Code Examples for com.jogamp.opengl.GL4#glActiveTexture()
The following examples show how to use
com.jogamp.opengl.GL4#glActiveTexture() .
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_texture_fetch_dependent.java From jogl-samples with MIT License | 6 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.DIFFUSE)); gl4.glActiveTexture(GL_TEXTURE1); gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.INDIRECTION)); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); return true; }
Example 2
Source File: TextureManager.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
int initTextureArray(TextureProvider textureProvider, GL4 gl) { if (!allTexturesLoaded(textureProvider)) { return -1; } Texture[] textures = textureProvider.getTextures(); int textureArrayId = GLUtil.glGenTexture(gl); gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, textureArrayId); gl.glTexStorage3D(gl.GL_TEXTURE_2D_ARRAY, 1, gl.GL_RGBA8, TEXTURE_SIZE, TEXTURE_SIZE, textures.length); gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST); gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST); gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE); // Set brightness to 1.0d to upload unmodified textures to GPU double save = textureProvider.getBrightness(); textureProvider.setBrightness(1.0d); updateTextures(textureProvider, gl, textureArrayId); textureProvider.setBrightness(save); gl.glActiveTexture(gl.GL_TEXTURE1); gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, textureArrayId); gl.glActiveTexture(gl.GL_TEXTURE0); return textureArrayId; }
Example 3
Source File: Gl_420_image_load.java From jogl-samples with MIT License | 5 votes |
private boolean initTexture(GL4 gl4) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl4.glGenTextures(1, textureName); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl4.glTexStorage2D(GL_TEXTURE_2D, texture.levels(), format.internal.value, texture.dimensions()[0], texture.dimensions()[1]); for (int level = 0; level < texture.levels(); ++level) { gl4.glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, texture.dimensions(level)[0], texture.dimensions(level)[1], format.external.value, format.type.value, texture.data(level)); } imageSize.set(texture.dimensions()); gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } catch (IOException ex) { Logger.getLogger(Gl_420_image_load.class.getName()).log(Level.SEVERE, null, ex); } return true; }
Example 4
Source File: Gl_400_fbo_layered.java From jogl-samples with MIT License | 5 votes |
private boolean initTexture(GL4 gl4) { gl4.glGenTextures(1, textureColorbufferName); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureColorbufferName.get(0)); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); gl4.glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, GL_RGB, windowSize.x / FRAMEBUFFER_SIZE, windowSize.y / FRAMEBUFFER_SIZE, 4, //depth 0, GL_RGB, GL_UNSIGNED_BYTE, null); return checkError(gl4, "initTexture"); }
Example 5
Source File: Gl_410_program_binary.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(viewMat4()).mul(model); gl4.glProgramUniformMatrix4fv(programName[Program.VERT], uniformMvp, 1, false, mvp.toFa_(), 0); gl4.glProgramUniform1i(programName[Program.FRAG], uniformDiffuse, 0); gl4.glViewportIndexedfv(0, viewportBuffer.put(0, 0).put(1, 0).put(2, windowSize.x).put(3, windowSize.y)); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0)); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); //!\ Need to be called after glBindVertexArray gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0); return true; }
Example 6
Source File: Gl_430_draw_without_vertex_attrib.java From jogl-samples with MIT License | 5 votes |
private boolean initTexture(GL4 gl4) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); assert (!texture.empty()); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl4.glGenTextures(1, textureName); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl4.glTexStorage2D(GL_TEXTURE_2D, texture.levels(), format.internal.value, texture.dimensions(0)[0], texture.dimensions(0)[1]); for (int level = 0; level < texture.levels(); ++level) { gl4.glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, texture.dimensions(level)[0], texture.dimensions(level)[1], format.external.value, format.type.value, texture.data(level)); } gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } catch (IOException ex) { Logger.getLogger(Gl_430_draw_without_vertex_attrib.class.getName()).log(Level.SEVERE, null, ex); } return true; }
Example 7
Source File: Gl_400_sampler_array_nv.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 1000.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(viewMat4()).mul(model); gl4.glViewport(0, 0, windowSize.x, windowSize.y); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0.5f).put(2, 0).put(3, 1)); gl4.glUseProgram(programName); gl4.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0); gl4.glUniform1i(uniformDiffuseRGB, 0); gl4.glUniform1i(uniformDiffuseBGR, 1); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.RGB)); gl4.glBindSampler(0, samplerName.get(0)); gl4.glActiveTexture(GL_TEXTURE1); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.BGR)); gl4.glBindSampler(1, samplerName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0); return true; }
Example 8
Source File: Gl_430_texture_storage.java From jogl-samples with MIT License | 5 votes |
private boolean initTexture(GL4 gl4) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl4.glGenTextures(1, textureName); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0)); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY, texture.levels(), format.internal.value, texture.dimensions(0)[0], texture.dimensions(0)[1], 1); for (int level = 0; level < texture.levels(); ++level) { gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, 0, texture.dimensions(level)[0], texture.dimensions(level)[1], 1, format.external.value, format.type.value, texture.data(level)); } gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } catch (IOException ex) { Logger.getLogger(Gl_430_texture_storage.class.getName()).log(Level.SEVERE, null, ex); } return true; }
Example 9
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 10
Source File: Gl_420_texture_conversion.java From jogl-samples with MIT License | 5 votes |
private boolean initTexture(GL4 gl4) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); assert (!texture.empty()); gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl4.glGenTextures(Texture.MAX, textureName); gl4.glActiveTexture(GL_TEXTURE0); for (int i = 0; i < Texture.MAX; ++i) { gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(i)); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl4.glTexStorage2D(GL_TEXTURE_2D, texture.levels(), textureInternalFormat[i], texture.dimensions(0)[0], texture.dimensions(0)[1]); for (int level = 0; level < texture.levels(); ++level) { gl4.glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, texture.dimensions(level)[0], texture.dimensions(level)[1], textureFormat[i], GL_UNSIGNED_BYTE, texture.data(level)); } } gl4.glBindTexture(GL_TEXTURE_2D, 0); gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } catch (IOException ex) { Logger.getLogger(Gl_420_texture_conversion.class.getName()).log(Level.SEVERE, null, ex); } return true; }
Example 11
Source File: TextureManager.java From plugins with GNU General Public License v3.0 | 5 votes |
int initTextureArray(TextureProvider textureProvider, GL4 gl) { if (!allTexturesLoaded(textureProvider)) { return -1; } Texture[] textures = textureProvider.getTextures(); int textureArrayId = GLUtil.glGenTexture(gl); gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, textureArrayId); gl.glTexStorage3D(gl.GL_TEXTURE_2D_ARRAY, 1, gl.GL_RGBA8, TEXTURE_SIZE, TEXTURE_SIZE, textures.length); gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST); gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST); gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE); // Set brightness to 1.0d to upload unmodified textures to GPU double save = textureProvider.getBrightness(); textureProvider.setBrightness(1.0d); updateTextures(textureProvider, gl, textureArrayId); textureProvider.setBrightness(save); gl.glActiveTexture(gl.GL_TEXTURE1); gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, textureArrayId); gl.glActiveTexture(gl.GL_TEXTURE0); return textureArrayId; }
Example 12
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; }
Example 13
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 14
Source File: Gl_430_texture_buffer.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.identity()).toFa_()); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); float[] depth = {1.0f}; gl4.glClearBufferfv(GL_DEPTH, 0, depth, 0); gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0); gl4.glUseProgram(programName); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_BUFFER, textureName.get(Texture.DISPLACEMENT)); gl4.glActiveTexture(GL_TEXTURE1); gl4.glBindTexture(GL_TEXTURE_BUFFER, 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.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 5, 0); return true; }
Example 15
Source File: Gl_400_fbo_layered.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; Mat4 projection = glm.ortho_(-1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f); Mat4 view = new Mat4(1.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(view).mul(model); gl4.glViewport(0, 0, windowSize.x, windowSize.y); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0)); // Pass 1 { gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl4.glViewport(0, 0, windowSize.x / FRAMEBUFFER_SIZE, windowSize.y / FRAMEBUFFER_SIZE); gl4.glUseProgram(programName[Program.LAYERING]); gl4.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0); gl4.glBindVertexArray(vertexArrayName.get(Program.LAYERING)); gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); } // Pass 2 { gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl4.glUseProgram(programName[Program.IMAGE_2D]); gl4.glUniform1i(uniformDiffuse, 0); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureColorbufferName.get(0)); gl4.glBindSampler(0, samplerName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(Program.IMAGE_2D)); for (int i = 0; i < 4; ++i) { gl4.glUniform1i(uniformLayer, i); gl4.glViewport(viewport[i].x, viewport[i].y, viewport[i].z, viewport[i].w); gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); } } return true; }
Example 16
Source File: Gl_450_query_statistics_arb.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.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(0)); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBeginQuery(GL_VERTICES_SUBMITTED_ARB, queryName.get(Statistics.VERTICES_SUBMITTED)); gl4.glBeginQuery(GL_PRIMITIVES_SUBMITTED_ARB, queryName.get(Statistics.PRIMITIVES_SUBMITTED)); gl4.glBeginQuery(GL_VERTEX_SHADER_INVOCATIONS_ARB, queryName.get(Statistics.VERTEX_SHADER_INVOCATIONS)); gl4.glBeginQuery(GL_TESS_CONTROL_SHADER_PATCHES_ARB, queryName.get(Statistics.TESS_CONTROL_SHADER_PATCHES)); gl4.glBeginQuery(GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB, queryName.get(Statistics.TESS_EVALUATION_SHADER_INVOCATIONS)); gl4.glBeginQuery(GL_GEOMETRY_SHADER_INVOCATIONS, queryName.get(Statistics.GEOMETRY_SHADER_INVOCATIONS)); gl4.glBeginQuery(GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB, queryName.get(Statistics.GEOMETRY_SHADER_PRIMITIVES_EMITTED)); gl4.glBeginQuery(GL_FRAGMENT_SHADER_INVOCATIONS_ARB, queryName.get(Statistics.FRAGMENT_SHADER_INVOCATIONS)); gl4.glBeginQuery(GL_COMPUTE_SHADER_INVOCATIONS_ARB, queryName.get(Statistics.COMPUTE_SHADER_INVOCATIONS)); gl4.glBeginQuery(GL_CLIPPING_INPUT_PRIMITIVES_ARB, queryName.get(Statistics.CLIPPING_INPUT_PRIMITIVES)); gl4.glBeginQuery(GL_CLIPPING_OUTPUT_PRIMITIVES_ARB, queryName.get(Statistics.CLIPPING_OUTPUT_PRIMITIVES)); { gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); } gl4.glEndQuery(GL_VERTICES_SUBMITTED_ARB); gl4.glEndQuery(GL_PRIMITIVES_SUBMITTED_ARB); gl4.glEndQuery(GL_VERTEX_SHADER_INVOCATIONS_ARB); gl4.glEndQuery(GL_TESS_CONTROL_SHADER_PATCHES_ARB); gl4.glEndQuery(GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB); gl4.glEndQuery(GL_GEOMETRY_SHADER_INVOCATIONS); gl4.glEndQuery(GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB); gl4.glEndQuery(GL_FRAGMENT_SHADER_INVOCATIONS_ARB); gl4.glEndQuery(GL_COMPUTE_SHADER_INVOCATIONS_ARB); gl4.glEndQuery(GL_CLIPPING_INPUT_PRIMITIVES_ARB); gl4.glEndQuery(GL_CLIPPING_OUTPUT_PRIMITIVES_ARB); IntBuffer queryResult = GLBuffers.newDirectIntBuffer(Statistics.MAX); for (int i = 0; i < queryResult.capacity(); ++i) { gl4.glGetQueryObjectuiv(queryName.get(i), GL_QUERY_RESULT, queryResult); } System.out.println("Verts: " + queryResult.get(Statistics.VERTICES_SUBMITTED) + "; Prims: (" + queryResult.get(Statistics.PRIMITIVES_SUBMITTED) + ", " + queryResult.get(Statistics.GEOMETRY_SHADER_PRIMITIVES_EMITTED) + "); Shaders(" + queryResult.get(Statistics.VERTEX_SHADER_INVOCATIONS) + ", " + queryResult.get(Statistics.TESS_CONTROL_SHADER_PATCHES) + ", " + queryResult.get(Statistics.TESS_EVALUATION_SHADER_INVOCATIONS) + ", " + queryResult.get(Statistics.GEOMETRY_SHADER_INVOCATIONS) + ", " + queryResult.get(Statistics.FRAGMENT_SHADER_INVOCATIONS) + ", " + queryResult.get(Statistics.COMPUTE_SHADER_INVOCATIONS) + "); Clip(" + queryResult.get(Statistics.CLIPPING_INPUT_PRIMITIVES) + ", " + queryResult.get(Statistics.CLIPPING_OUTPUT_PRIMITIVES) + ")\r"); return true; }
Example 17
Source File: Gl_420_texture_compressed.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 | 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); projection.mul(viewMat4()).mul(model).toDbb(pointer); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } // Clear the color buffer gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1.0f).put(1, 0.5f).put(2, 0.0f).put(3, 1.0f)); // Bind rendering objects gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindSampler(0, samplerName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); // Draw each texture in different viewports for (int index = 0; index < Texture.MAX; ++index) { gl4.glViewportIndexedfv(0, viewport[index].toDfb(viewportBuffer)); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(index)); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); } return true; }
Example 18
Source File: Gl_410_fbo_layered.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; Mat4 projection = glm.ortho_(-1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f); Mat4 view = new Mat4(1.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(view).mul(model); gl4.glProgramUniformMatrix4fv(programName[Program.LAYERING], uniformMvp[Program.LAYERING], 1, false, mvp.toFa_(), 0); gl4.glProgramUniformMatrix4fv(programName[Program.VIEWPORT], uniformMvp[Program.VIEWPORT], 1, false, mvp.toFa_(), 0); gl4.glProgramUniform1i(programName[Program.VIEWPORT], uniformDiffuse, 0); // Pass 1 { gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl4.glViewportIndexedfv(0, viewportBuffer.put(0, 0).put(1, 0).put(2, FRAMEBUFFER_SIZE.x).put(3, FRAMEBUFFER_SIZE.y)); gl4.glUseProgram(programName[Program.LAYERING]); gl4.glBindVertexArray(vertexArrayName.get(Program.LAYERING)); gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); } // Pass 2 { int border = 2; gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0)); gl4.glViewportIndexedfv(0, viewportBuffer.put(0, border).put(1, border).put(2, windowSize.x * 0.5f - 2.0f * border) .put(3, windowSize.y * 0.5f - 2.0f * border)); gl4.glViewportIndexedfv(1, viewportBuffer.put(0, windowSize.x * 0.5f + border).put(1, border) .put(2, windowSize.x * 0.5f - 2.0f * border).put(3, windowSize.y * 0.5f - 2.0f * border)); gl4.glViewportIndexedfv(2, viewportBuffer.put(0, windowSize.x * 0.5f + border).put(1, windowSize.y * 0.5f + 1) .put(2, windowSize.x * 0.5f - 2.0f * border).put(3, windowSize.y * 0.5f - 2.0f * border)); gl4.glViewportIndexedfv(3, viewportBuffer.put(0, border).put(1, windowSize.y * 0.5f + border) .put(2, windowSize.x * 0.5f - 2.0f * border).put(3, windowSize.y * 0.5f - 2.0f * border)); gl4.glUseProgram(programName[Program.VIEWPORT]); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0)); gl4.glBindSampler(0, samplerName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(Program.VIEWPORT)); gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); } return true; }
Example 19
Source File: Gl_430_program_compute_variable_group_size.java From jogl-samples with MIT License | 4 votes |
private boolean initTexture(GL4 gl4) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); assert (!texture.empty()); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl4.glGenTextures(Texture.MAX, textureName); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.INPUT)); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl4.glTexStorage2D(GL_TEXTURE_2D, texture.levels(), format.internal.value, texture.dimensions()[0], texture.dimensions()[1]); for (int level = 0; level < texture.levels(); ++level) { gl4.glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, texture.dimensions(level)[0], texture.dimensions(level)[1], format.external.value, format.type.value, texture.data(level)); } gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.OUTPUT)); gl4.glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, texture.dimensions()[0], texture.dimensions()[1]); textureSize = new Vec2i(texture.dimensions()[0], texture.dimensions()[1]); } catch (IOException ex) { Logger.getLogger(Gl_430_program_compute.class.getName()).log(Level.SEVERE, null, ex); } return true; }
Example 20
Source File: Gl_440_fbo_without_attachment.java From jogl-samples with MIT License | 4 votes |
private boolean initTexture(GL4 gl4) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); assert (!texture.empty()); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); jgli.Gl.Swizzles swizzles = jgli.Gl.translate(texture.swizzles()); gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl4.glGenTextures(Texture.MAX, textureName, 0); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName[Texture.DIFFUSE]); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, swizzles.r.value); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, swizzles.g.value); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, swizzles.b.value); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, swizzles.a.value); gl4.glTexStorage2D(GL_TEXTURE_2D, texture.levels(), format.internal.value, texture.dimensions()[0], texture.dimensions()[1]); for (int level = 0; level < texture.levels(); ++level) { gl4.glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, texture.dimensions(level)[0], texture.dimensions(level)[1], format.external.value, format.type.value, texture.data(level)); } gl4.glBindTexture(GL_TEXTURE_2D, textureName[Texture.COLORBUFFER]); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); gl4.glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, windowSize.x * supersampling, windowSize.y * supersampling); gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } catch (IOException ex) { Logger.getLogger(Gl_440_fbo_without_attachment.class.getName()).log(Level.SEVERE, null, ex); } return true; }