Java Code Examples for com.jogamp.opengl.GL3#glGenerateMipmap()
The following examples show how to use
com.jogamp.opengl.GL3#glGenerateMipmap() .
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_320_primitive_sprite.java From jogl-samples with MIT License | 5 votes |
private boolean initTexture(GL3 gl3) { try { gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl3.glGenTextures(1, textureName); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); assert (!texture.empty()); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); for (int level = 0; level < texture.levels(); ++level) { gl3.glTexImage2D(GL_TEXTURE_2D, level, format.internal.value, texture.dimensions(level)[0], texture.dimensions(level)[1], 0, format.external.value, format.type.value, texture.data(level)); } gl3.glGenerateMipmap(GL_TEXTURE_2D); gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } catch (IOException ex) { Logger.getLogger(Gl_320_primitive_sprite.class.getName()).log(Level.SEVERE, null, ex); } return true; }
Example 2
Source File: Gl_320_glsl_precision.java From jogl-samples with MIT License | 5 votes |
protected boolean initTexture(GL3 gl3) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); assert (!texture.empty()); gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl3.glGenTextures(1, textureName); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); for (int level = 0; level < texture.levels(); ++level) { gl3.glTexImage2D(GL_TEXTURE_2D, level, format.internal.value, texture.dimensions(level)[0], texture.dimensions(level)[1], 0, format.external.value, format.type.value, texture.data(level)); } if (texture.levels() == 1) { gl3.glGenerateMipmap(GL_TEXTURE_2D); } gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } catch (IOException ex) { Logger.getLogger(Gl_320_glsl_precision.class.getName()).log(Level.SEVERE, null, ex); } return checkError(gl3, "initTexture"); }
Example 3
Source File: Gl_320_glsl_builtin_blocks.java From jogl-samples with MIT License | 5 votes |
private boolean initTexture(GL3 gl3) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); assert (!texture.empty()); gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl3.glGenTextures(1, textureName); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); for (int level = 0; level < texture.levels(); ++level) { gl3.glTexImage2D(GL_TEXTURE_2D, level, format.internal.value, texture.dimensions(level)[0], texture.dimensions(level)[1], 0, format.external.value, format.type.value, texture.data(level)); } gl3.glGenerateMipmap(GL_TEXTURE_2D); gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } catch (IOException ex) { Logger.getLogger(Gl_320_glsl_builtin_blocks.class.getName()).log(Level.SEVERE, null, ex); } return checkError(gl3, "initTexture"); }
Example 4
Source File: Gl_320_texture_integer.java From jogl-samples with MIT License | 5 votes |
private boolean initTexture(GL3 gl3) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl3.glGenTextures(1, textureName); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); for (int level = 0; level < texture.levels(); ++level) { // TODO fix format gl3.glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8UI, // TODO -A? texture.dimensions(level)[0], texture.dimensions(level)[1], 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, texture.data(level)); } gl3.glGenerateMipmap(GL_TEXTURE_2D); gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } catch (IOException ex) { Logger.getLogger(Gl_320_texture_integer.class.getName()).log(Level.SEVERE, null, ex); } return checkError(gl3, "initTexture"); }
Example 5
Source File: Gl_320_glsl_input_struct.java From jogl-samples with MIT License | 4 votes |
private boolean initTexture(GL3 gl3) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); assert (!texture.empty()); gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl3.glGenTextures(1, textureName); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); for (int level = 0; level < texture.levels(); ++level) { gl3.glTexImage2D(GL_TEXTURE_2D, level, format.internal.value, texture.dimensions(level)[0], texture.dimensions(level)[1], 0, format.external.value, format.type.value, texture.data(level)); } if (texture.levels() == 1) { gl3.glGenerateMipmap(GL_TEXTURE_2D); } gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } catch (IOException ex) { Logger.getLogger(Gl_320_glsl_input_struct.class.getName()).log(Level.SEVERE, null, ex); } return checkError(gl3, "initTexture"); }
Example 6
Source File: Gl_320_fbo_blit.java From jogl-samples with MIT License | 4 votes |
private boolean initTexture(GL3 gl3) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); gl3.glGenTextures(Texture.MAX, textureName); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); for (int level = 0; level < texture.levels(); level++) { gl3.glTexImage2D(GL_TEXTURE_2D, level, format.internal.value, texture.dimensions(level)[0], texture.dimensions(level)[1], 0, format.external.value, format.type.value, texture.data(level)); } gl3.glGenerateMipmap(GL_TEXTURE_2D); // Allocate all mipmaps memory gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER)); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl3.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, null); gl3.glBindTexture(GL_TEXTURE_2D, 0); } catch (IOException ex) { Logger.getLogger(Gl_320_fbo_blit.class.getName()).log(Level.SEVERE, null, ex); } return true; }
Example 7
Source File: Gl_320_fbo_blit.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; gl3.glUseProgram(programName); gl3.glUniform1i(uniformDiffuse, 0); // Pass 1 gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER)); gl3.glViewport(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{0.0f, 0.5f, 1.0f, 1.0f}, 0); renderFBO(gl3); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); // Generate FBO mipmaps gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER)); gl3.glGenerateMipmap(GL_TEXTURE_2D); gl3.glBindTexture(GL_TEXTURE_2D, 0); // Blit framebuffers int border = 2; int tile = 4; gl3.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER)); gl3.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE)); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0); for (int j = 0; j < tile; ++j) { for (int i = 0; i < tile; ++i) { if (((i + j) % 2) != 0) { continue; } gl3.glBlitFramebuffer(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, FRAMEBUFFER_SIZE.x / tile * (i + 0) + border, FRAMEBUFFER_SIZE.x / tile * (j + 0) + border, FRAMEBUFFER_SIZE.y / tile * (i + 1) - border, FRAMEBUFFER_SIZE.y / tile * (j + 1) - border, GL_COLOR_BUFFER_BIT, GL_LINEAR); } } // Pass 2 gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0); renderFB(gl3); return true; }
Example 8
Source File: Gl_320_texture_3d.java From jogl-samples with MIT License | 4 votes |
private boolean initTexture(GL3 gl3) { int size = 32; FloatBuffer data = GLBuffers.newDirectFloatBuffer(size * size * size); for (int k = 0; k < size; ++k) { for (int j = 0; j < size; ++j) { for (int i = 0; i < size; ++i) { data.put(i + j * size + k * size * size, new Vec4(i, j, k, 0.0f).div(size / 8 - 1).simplex_()); } } } gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl3.glGenTextures(1, textureName); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_3D, textureName.get(0)); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, (int) (Math.log(256) / Math.log(2))); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); gl3.glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, size, size, size, 0, GL_RED, GL_FLOAT, data); gl3.glGenerateMipmap(GL_TEXTURE_3D); BufferUtils.destroyDirectBuffer(data); gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return checkError(gl3, "initTexture"); }
Example 9
Source File: Gl_320_texture_2d.java From jogl-samples with MIT License | 4 votes |
private boolean initTexture(GL3 gl3) { try { jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); assert (!texture.empty()); gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl3.glGenTextures(1, textureName); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture.levels() == 1 ? GL_NEAREST : GL_NEAREST_MIPMAP_NEAREST); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gl3.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, -1000.f); gl3.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 1000.f); gl3.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, 0.0f); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); for (int level = 0; level < texture.levels(); ++level) { gl3.glTexImage2D(GL_TEXTURE_2D, level, format.internal.value, texture.dimensions(level)[0], texture.dimensions(level)[1], 0, format.external.value, format.type.value, texture.data(level)); } if (texture.levels() == 1) { gl3.glGenerateMipmap(GL_TEXTURE_2D); } gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } catch (IOException ex) { Logger.getLogger(Gl_320_texture_2d.class.getName()).log(Level.SEVERE, null, ex); } return true; }
Example 10
Source File: Gl_320_texture_derivative.java From jogl-samples with MIT License | 4 votes |
private boolean initTexture(GL3 gl3) { jgli.Texture2d texture = new Texture2d(jgli.Format.FORMAT_RGBA8_UNORM_PACK32, new int[]{64, 64}); texture.clear(0, 0, 0, new byte[]{(byte) 255, (byte) 0, (byte) 0, (byte) 255}); texture.clear(0, 0, 1, new byte[]{(byte) 255, (byte) 128, (byte) 0, (byte) 255}); texture.clear(0, 0, 2, new byte[]{(byte) 255, (byte) 255, (byte) 0, (byte) 255}); texture.clear(0, 0, 3, new byte[]{(byte) 0, (byte) 255, (byte) 0, (byte) 255}); texture.clear(0, 0, 4, new byte[]{(byte) 0, (byte) 255, (byte) 255, (byte) 255}); texture.clear(0, 0, 5, new byte[]{(byte) 0, (byte) 0, (byte) 255, (byte) 255}); texture.clear(0, 0, 6, new byte[]{(byte) 255, (byte) 0, (byte) 0, (byte) 255}); gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl3.glGenTextures(1, textureName); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); for (int level = 0; level < texture.levels(); ++level) { gl3.glTexImage2D(GL_TEXTURE_2D, level, format.internal.value, texture.dimensions(level)[0], texture.dimensions(level)[1], 0, format.external.value, format.type.value, texture.data(level)); } if (texture.levels() == 1) { gl3.glGenerateMipmap(GL_TEXTURE_2D); } gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return true; }