List of usage examples for org.lwjgl.opengl EXTFramebufferObject glGenerateMipmapEXT
public static native void glGenerateMipmapEXT(@NativeType("GLenum") int target);
From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java
License:Open Source License
/** * <code>setupTexture</code> initializes a new Texture object for use with TextureRenderer. Generates a valid OpenGL * texture id for this texture and initializes the data type for the texture. *///from w ww. j a v a 2 s. c o m public void setupTexture(final Texture tex) { if (tex.getType() != Type.TwoDimensional && tex.getType() != Type.CubeMap) { throw new IllegalArgumentException("Texture type not supported: " + tex.getType()); } final RenderContext context = ContextManager.getCurrentContext(); final TextureStateRecord record = (TextureStateRecord) context .getStateRecord(RenderState.StateType.Texture); // check if we are already setup... if so, throw error. if (tex.getTextureKey() == null) { tex.setTextureKey(TextureKey.getRTTKey(tex.getMinificationFilter())); } else if (tex.getTextureIdForContext(context.getGlContextRep()) != 0) { throw new Ardor3dException("Texture is already setup and has id."); } // Create the texture final IntBuffer ibuf = BufferUtils.createIntBuffer(1); GL11.glGenTextures(ibuf); final int textureId = ibuf.get(0); tex.setTextureIdForContext(context.getGlContextRep(), textureId); LwjglTextureStateUtil.doTextureBind(tex, 0, true); // Initialize our texture with some default data. final int internalFormat = LwjglTextureUtil.getGLInternalFormat(tex.getTextureStoreFormat()); final int dataFormat = LwjglTextureUtil.getGLPixelFormatFromStoreFormat(tex.getTextureStoreFormat()); final int pixelDataType = LwjglTextureUtil.getGLPixelDataType(tex.getRenderedTexturePixelDataType()); if (tex.getType() == Type.TwoDimensional) { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, internalFormat, _width, _height, 0, dataFormat, pixelDataType, (ByteBuffer) null); } else { for (final Face face : Face.values()) { GL11.glTexImage2D(LwjglTextureStateUtil.getGLCubeMapFace(face), 0, internalFormat, _width, _height, 0, dataFormat, pixelDataType, (ByteBuffer) null); } } // Initialize mipmapping for this texture, if requested if (tex.getMinificationFilter().usesMipMapLevels()) { EXTFramebufferObject.glGenerateMipmapEXT(LwjglTextureStateUtil.getGLType(tex.getType())); } // Setup filtering and wrap final TextureRecord texRecord = record.getTextureRecord(textureId, tex.getType()); LwjglTextureStateUtil.applyFilter(tex, texRecord, 0, record, context.getCapabilities()); LwjglTextureStateUtil.applyWrap(tex, texRecord, 0, record, context.getCapabilities()); logger.fine("setup fbo tex with id " + textureId + ": " + _width + "," + _height); }
From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java
License:Open Source License
private void render(final List<? extends Spatial> toDrawA, final Spatial toDrawB, final Scene toDrawC, final List<Texture> texs, final int clear) { final int maxDrawBuffers = ContextManager.getCurrentContext().getCapabilities().getMaxFBOColorAttachments(); // if we only support 1 draw buffer at a time anyway, we'll have to render to each texture individually... if (maxDrawBuffers == 1 || texs.size() == 1) { try {/*from ww w.j ava 2s .co m*/ ContextManager.getCurrentContext().pushFBOTextureRenderer(this); for (int i = 0; i < texs.size(); i++) { final Texture tex = texs.get(i); setupForSingleTexDraw(tex); if (_samples > 0 && _supportsMultisample) { setMSFBO(); } switchCameraIn(clear); if (toDrawA != null) { doDraw(toDrawA); } else if (toDrawB != null) { doDraw(toDrawB); } else { doDraw(toDrawC); } switchCameraOut(); if (_samples > 0 && _supportsMultisample) { blitMSFBO(); } takedownForSingleTexDraw(tex); } } finally { ContextManager.getCurrentContext().popFBOTextureRenderer(); } return; } try { ContextManager.getCurrentContext().pushFBOTextureRenderer(this); // Otherwise, we can streamline this by rendering to multiple textures at once. // first determine how many groups we need final LinkedList<Texture> depths = new LinkedList<Texture>(); final LinkedList<Texture> colors = new LinkedList<Texture>(); for (int i = 0; i < texs.size(); i++) { final Texture tex = texs.get(i); if (tex.getTextureStoreFormat().isDepthFormat()) { depths.add(tex); } else { colors.add(tex); } } // we can only render to 1 depth texture at a time, so # groups is at minimum == numDepth final int groups = Math.max(depths.size(), (int) Math.ceil(colors.size() / (float) maxDrawBuffers)); final RenderContext context = ContextManager.getCurrentContext(); for (int i = 0; i < groups; i++) { // First handle colors int colorsAdded = 0; while (colorsAdded < maxDrawBuffers && !colors.isEmpty()) { final Texture tex = colors.removeFirst(); if (tex.getType() == Type.TwoDimensional) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT + colorsAdded, GL11.GL_TEXTURE_2D, tex.getTextureIdForContext(context.getGlContextRep()), 0); } else if (tex.getType() == Type.CubeMap) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT + colorsAdded, LwjglTextureStateUtil.getGLCubeMapFace(((TextureCubeMap) tex).getCurrentRTTFace()), tex.getTextureIdForContext(context.getGlContextRep()), 0); } else { throw new IllegalArgumentException("Invalid texture type: " + tex.getType()); } colorsAdded++; } // Now take care of depth. if (!depths.isEmpty()) { final Texture tex = depths.removeFirst(); // Set up our depth texture if (tex.getType() == Type.TwoDimensional) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D, tex.getTextureIdForContext(context.getGlContextRep()), 0); } else if (tex.getType() == Type.CubeMap) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, LwjglTextureStateUtil.getGLCubeMapFace(((TextureCubeMap) tex).getCurrentRTTFace()), tex.getTextureIdForContext(context.getGlContextRep()), 0); } else { throw new IllegalArgumentException("Invalid texture type: " + tex.getType()); } _usingDepthRB = false; } else if (!_usingDepthRB) { // setup our default depth render buffer if not already set EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRBID); _usingDepthRB = true; } setDrawBuffers(colorsAdded); setReadBuffer(colorsAdded != 0 ? EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT : GL11.GL_NONE); // Check FBO complete checkFBOComplete(_fboID); switchCameraIn(clear); if (toDrawA != null) { doDraw(toDrawA); } else { doDraw(toDrawB); } switchCameraOut(); } // automatically generate mipmaps for our textures. for (int x = 0, max = texs.size(); x < max; x++) { if (texs.get(x).getMinificationFilter().usesMipMapLevels()) { final Texture tex = texs.get(x); if (tex.getMinificationFilter().usesMipMapLevels()) { LwjglTextureStateUtil.doTextureBind(texs.get(x), 0, true); EXTFramebufferObject.glGenerateMipmapEXT(LwjglTextureStateUtil.getGLType(tex.getType())); } } } } finally { ContextManager.getCurrentContext().popFBOTextureRenderer(); } }
From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java
License:Open Source License
@Override protected void takedownForSingleTexDraw(final Texture tex) { // automatically generate mipmaps for our texture. if (tex.getMinificationFilter().usesMipMapLevels()) { LwjglTextureStateUtil.doTextureBind(tex, 0, true); EXTFramebufferObject.glGenerateMipmapEXT(LwjglTextureStateUtil.getGLType(tex.getType())); }/*w w w .ja v a2 s.c o m*/ }
From source file:com.badlogic.gdx.backends.jglfw.JglfwGL20.java
License:Apache License
public void glGenerateMipmap(int target) { EXTFramebufferObject.glGenerateMipmapEXT(target); }
From source file:io.root.gfx.glutils.GL.java
License:Apache License
public static void glGenerateMipmap(int target) { EXTFramebufferObject.glGenerateMipmapEXT(target); }
From source file:io.root.gfx.sprites.Sprite.java
License:Apache License
/** * Load a texture from the given path, with the specified filters and wrap, * also controls whether to generate a mipmap * //from w w w. jav a 2 s. c o m * @param path * @param minFilter * @param magFilter * @param wrap * @param genMipmap */ public Sprite(String path, int minFilter, int magFilter, int wrap, boolean genMipmap) { InputStream input = null; try { input = getClass().getResource(path).openStream(); PNGDecoder dec = new PNGDecoder(input); width = dec.getWidth(); height = dec.getHeight(); ByteBuffer buf = BufferUtils.createByteBuffer(4 * width * height); dec.decode(buf, width * 4, PNGDecoder.Format.RGBA); buf.flip(); id = GL.glGenTextures(); bind(); setFilter(minFilter, magFilter); setWrap(wrap); upload(GL.GL_RGBA, buf); if (genMipmap) { EXTFramebufferObject.glGenerateMipmapEXT(getTarget()); } } catch (IOException e) { throw new RootException("could not load texture: " + e.getMessage()); } finally { if (input != null) { try { input.close(); } catch (IOException e) { } } } }
From source file:mwisbest.openbase.opengl.TextureLoader.java
License:Open Source License
private TextureImplementation getTexture(InputStream in, String resourceName, int target, int minFilter, int magFilter, boolean flipped, int[] transparent) throws IOException { // create the texture ID for this texture ByteBuffer textureBuffer;/*from w w w . jav a2 s . co m*/ LoadableImageData imageData = ImageDataFactory.getImageDataFor(resourceName); textureBuffer = imageData.loadImage(new BufferedInputStream(in), flipped, transparent); int textureID = createTextureID(); TextureImplementation texture = new TextureImplementation(resourceName, target, textureID); // bind this texture GL11.glEnable(target); GL11.glBindTexture(target, textureID); int width; int height; int texWidth; int texHeight; ImageData.Format format; width = imageData.getWidth(); height = imageData.getHeight(); format = imageData.getFormat(); texture.setTextureWidth(imageData.getTexWidth()); texture.setTextureHeight(imageData.getTexHeight()); texWidth = texture.getTextureWidth(); texHeight = texture.getTextureHeight(); IntBuffer temp = BufferUtils.createIntBuffer(16); GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE, temp); int max = temp.get(0); if (texWidth > max || texHeight > max) throw new IOException("Attempt to allocate a texture to big for the current hardware"); int srcPixelFormat = format.getOGLType(); texture.setWidth(width); texture.setHeight(height); texture.setImageFormat(format); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter); ContextCapabilities capabilities = GLContext.getCapabilities(); if (capabilities.OpenGL30 || capabilities.GL_EXT_framebuffer_object || capabilities.GL_ARB_framebuffer_object || capabilities.OpenGL14) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, GL11.GL_POLYGON_BIT); if (capabilities.OpenGL30) GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); else if (capabilities.GL_EXT_framebuffer_object) EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D); else if (capabilities.GL_ARB_framebuffer_object) ARBFramebufferObject.glGenerateMipmap(GL11.GL_TEXTURE_2D); else if (capabilities.OpenGL14) GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE); } // produce a texture from the byte buffer GL11.glTexImage2D(target, 0, this.dstPixelFormat, get2Fold(width), get2Fold(height), 0, srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer); return texture; }
From source file:org.getspout.spout.config.MipMapUtils.java
License:Open Source License
public static void onTick(int texture, float targetFade, float currentFade) { GL11.glPushMatrix();//from w w w . j av a 2 s . c o m GL11.glBindTexture(3553, texture); if (targetFade != currentFade) { if (targetFade < currentFade) { currentFade -= 0.01f; if (currentFade <= targetFade) { currentFade = targetFade; } } else { currentFade += 0.01f; if (currentFade >= targetFade) { currentFade = targetFade; } } if (currentFade <= 0.0f) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glAlphaFunc(GL11.GL_GREATER, 0.01F); //default blend state updateTerrain = false; GL11.glPopMatrix(); return; } else { GL11.glTexEnvf(GL14.GL_TEXTURE_FILTER_CONTROL, GL14.GL_TEXTURE_LOD_BIAS, getMipmapLevels(texture) * (currentFade - 1.0f)); } } switch (mode) { case 1: GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); break; case 2: EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D); break; } GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.3F); //more strict blend state GL11.glPopMatrix(); }
From source file:org.oscim.gdx.LwjglGL20.java
License:Apache License
public void generateMipmap(int target) { EXTFramebufferObject.glGenerateMipmapEXT(target); }
From source file:org.spoutcraft.client.config.MipMapUtils.java
License:Open Source License
public static void onTick(int texture, float targetFade, float currentFade) { GL11.glPushMatrix();/*from w w w . j av a 2s . c om*/ SpoutClient.getHandle().renderEngine.bindTexture(texture); if (targetFade != currentFade) { if (targetFade < currentFade) { currentFade -= 0.01f; if (currentFade <= targetFade) { currentFade = targetFade; } } else { currentFade += 0.01f; if (currentFade >= targetFade) { currentFade = targetFade; } } if (currentFade <= 0.0f) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glAlphaFunc(GL11.GL_GREATER, 0.01F); // Default blend state updateTerrain = false; GL11.glPopMatrix(); return; } else { GL11.glTexEnvf(GL14.GL_TEXTURE_FILTER_CONTROL, GL14.GL_TEXTURE_LOD_BIAS, getMipmapLevels(texture) * (currentFade - 1.0f)); } } switch (mode) { case 1: GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); break; case 2: EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D); break; } GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.3F); // More strict blend state GL11.glPopMatrix(); }