/** * Called by the Renderer when a texture has been set. * * @param image The image that was set * @param wasSwitched If true, the texture has required a state switch */ public void onTextureUse(Image image, boolean wasSwitched){ assert image.getId() >= 1; if( !enabled ) return; if (!texturesUsed.containsKey(image.getId())) texturesUsed.put(image.getId(), null); if (wasSwitched) numTextureBinds ++; }
/** * Get the identifier of the full (dual eye) texture. * * @return the identifier of the full (dual eye) texture. * @see #getLeftTexId() * @see #getRightTexId() */ private int getFullTexId() { return (int) dualEyeTex.getImage().getId(); }
/** * Get the identifier of the full (dual eye) texture. * @return the identifier of the full (dual eye) texture. * @see #getLeftTexId() * @see #getRightTexId() */ private int getFullTexId() { return (int)dualEyeTex.getImage().getId(); }
/** * Get the identifier of the right eye texture. * @return the identifier of the right eye texture. * @see #getLeftTexId() * @see #getFullTexId() */ protected int getRightTexId() { return (int)rightEyeTexture.getImage().getId(); }
/** * Get the identifier of the full (dual eye) texture. * @return the identifier of the full (dual eye) texture. * @see #getLeftTexId() * @see #getRightTexId() */ private int getFullTexId() { return (int)dualEyeTex.getImage().getId(); }
/** * Get the identifier of the left eye texture. * @return the identifier of the left eye texture. * @see #getRightTexId() * @see #getFullTexId() */ protected int getLeftTexId() { return (int)leftEyeTexture.getImage().getId(); }
@Override public String toString(){ StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()); sb.append("[size=").append(width).append("x").append(height); if (depth > 1) sb.append("x").append(depth); sb.append(", format=").append(format.name()); if (hasMipmaps()) sb.append(", mips"); if (getId() >= 0) sb.append(", id=").append(id); sb.append("]"); return sb.toString(); }
public void deleteImage(Image image) { int texId = image.getId(); if (texId != -1) { intBuf1.put(0, texId); intBuf1.position(0).limit(1); gl.glDeleteTextures(intBuf1); image.resetObject(); statistics.onDeleteTexture(); } }
/** * Get the identifier of the left eye texture. * * @return the identifier of the left eye texture. * @see #getRightTexId() * @see #getFullTexId() */ protected int getLeftTexId() { return (int) getLeftTexture().getImage().getId(); }
/** * Get the identifier of the left eye texture. * @return the identifier of the left eye texture. * @see #getRightTexId() * @see #getFullTexId() */ protected int getLeftTexId() { return (int)getLeftTexture().getImage().getId(); }
/** * Get the identifier of the right eye texture. * * @return the identifier of the right eye texture. * @see #getLeftTexId() * @see #getFullTexId() */ protected int getRightTexId() { return (int) getRightTexture().getImage().getId(); }
/** * Get the identifier of the right eye texture. * @return the identifier of the right eye texture. * @see #getLeftTexId() * @see #getFullTexId() */ protected int getRightTexId() { return (int)getRightTexture().getImage().getId(); }
@Override public Image bindImage(com.jme3.texture.Image image, Texture.Type textureType, int miplevel, MemoryAccess access) { int imageID = image.getId(); if (imageID == -1) { throw new IllegalArgumentException("image was not yet uploaded to the GPU"); } long memFlags = Utils.getMemoryAccessFlags(access); int textureTarget = convertTextureType(textureType); Utils.errorBuffer.rewind(); CLMem mem = CL12GL.clCreateFromGLTexture(context, memFlags, textureTarget, miplevel, imageID, Utils.errorBuffer); Utils.checkError(Utils.errorBuffer, "clCreateFromGLTexture"); return new LwjglImage(mem); }
@Override public Image bindImage(com.jme3.texture.Image image, Texture.Type textureType, int miplevel, MemoryAccess access) { int imageID = image.getId(); if (imageID == -1) { throw new IllegalArgumentException("image was not yet uploaded to the GPU"); } long memFlags = Utils.getMemoryAccessFlags(access); int textureTarget = convertTextureType(textureType); Utils.errorBuffer.rewind(); long mem; if (textureType == Texture.Type.TwoDimensional) { mem = ((CLGL) cl).clCreateFromGLTexture2D(id, memFlags, textureTarget, miplevel, imageID, Utils.errorBuffer); } else if (textureType == Texture.Type.ThreeDimensional) { mem = ((CLGL) cl).clCreateFromGLTexture3D(id, memFlags, textureTarget, miplevel, imageID, Utils.errorBuffer); } else { throw new UnsupportedOperationException("Jocl only supports 2D and 3D images"); } Utils.checkError(Utils.errorBuffer, "clCreateFromGLTexture"); return new JoclImage(mem); }
/** * Ensures that the texture is bound to the given unit, * but does not care if the unit is active (for rendering). * * @param target The texture target, one of GL_TEXTURE_*** * @param img The image texture to bind * @param unit At what unit to bind the texture. */ private void bindTextureOnly(int target, Image img, int unit) { if (context.boundTextures[unit] != img) { if (context.boundTextureUnit != unit) { gl.glActiveTexture(GL.GL_TEXTURE0 + unit); context.boundTextureUnit = unit; } gl.glBindTexture(target, img.getId()); context.boundTextures[unit] = img; statistics.onTextureUse(img, true); } else { statistics.onTextureUse(img, false); } }
/** * Ensures that the texture is bound to the given unit * and that the unit is currently active (for modification). * * @param target The texture target, one of GL_TEXTURE_*** * @param img The image texture to bind * @param unit At what unit to bind the texture. */ private void bindTextureAndUnit(int target, Image img, int unit) { if (context.boundTextureUnit != unit) { gl.glActiveTexture(GL.GL_TEXTURE0 + unit); context.boundTextureUnit = unit; } if (context.boundTextures[unit] != img) { gl.glBindTexture(target, img.getId()); context.boundTextures[unit] = img; statistics.onTextureUse(img, true); } else { statistics.onTextureUse(img, false); } }
@Override public Image bindImage(com.jme3.texture.Image image, Texture.Type textureType, int miplevel, MemoryAccess access) { Utils.assertSharingPossible(); int imageID = image.getId(); if (imageID == -1) { throw new IllegalArgumentException("image was not yet uploaded to the GPU"); } long memFlags = Utils.getMemoryAccessFlags(access); int textureTarget = convertTextureType(textureType); Utils.errorBuffer.rewind(); long mem = CL12GL.clCreateFromGLTexture(context, memFlags, textureTarget, miplevel, imageID, Utils.errorBuffer); Utils.checkError(Utils.errorBuffer, "clCreateFromGLTexture"); return new LwjglImage(mem); }
private void setupFinalFullTexture(Camera cam) { if (environment != null) { if (environment.getApplication() != null) { // create offscreen framebuffer FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1); //offBuffer.setSrgb(true); //setup framebuffer's texture dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8); dualEyeTex.setMinFilter(Texture2D.MinFilter.BilinearNoMipMaps); dualEyeTex.setMagFilter(Texture2D.MagFilter.Bilinear); logger.config("Dual eye texture " + dualEyeTex.getName() + " (" + dualEyeTex.getImage().getId() + ")"); logger.config(" Type: " + dualEyeTex.getType()); logger.config(" Size: " + dualEyeTex.getImage().getWidth() + "x" + dualEyeTex.getImage().getHeight()); logger.config(" Image depth: " + dualEyeTex.getImage().getDepth()); logger.config(" Image format: " + dualEyeTex.getImage().getFormat()); logger.config(" Image color space: " + dualEyeTex.getImage().getColorSpace()); //setup framebuffer to use texture out.setDepthBuffer(Image.Format.Depth); out.setColorTexture(dualEyeTex); ViewPort viewPort = environment.getApplication().getViewPort(); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black); viewPort.setOutputFrameBuffer(out); } else { throw new IllegalStateException("This VR environment is not attached to any application."); } } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
public void updateRenderTexture(FrameBuffer fb, RenderBuffer rb) { Texture tex = rb.getTexture(); Image image = tex.getImage(); if (image.isUpdateNeeded()) { // Check NPOT requirements checkNonPowerOfTwo(tex); updateTexImageData(image, tex.getType(), 0, false); // NOTE: For depth textures, sets nearest/no-mips mode // Required to fix "framebuffer unsupported" // for old NVIDIA drivers! setupTextureParams(0, tex); } if (rb.getLayer() < 0){ glfbo.glFramebufferTexture2DEXT(GLFbo.GL_FRAMEBUFFER_EXT, convertAttachmentSlot(rb.getSlot()), convertTextureType(tex.getType(), image.getMultiSamples(), rb.getFace()), image.getId(), 0); } else { glfbo.glFramebufferTextureLayerEXT(GLFbo.GL_FRAMEBUFFER_EXT, convertAttachmentSlot(rb.getSlot()), image.getId(), 0, rb.getLayer()); } }
@Override public void setTexture(int unit, Texture tex) { Image image = tex.getImage(); if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) { // Check NPOT requirements boolean scaleToPot = false; try { checkNonPowerOfTwo(tex); } catch (RendererException ex) { if (logger.isLoggable(Level.WARNING)) { int nextWidth = FastMath.nearestPowerOfTwo(tex.getImage().getWidth()); int nextHeight = FastMath.nearestPowerOfTwo(tex.getImage().getHeight()); logger.log(Level.WARNING, "Non-power-of-2 textures are not supported! Scaling texture '" + tex.getName() + "' of size " + tex.getImage().getWidth() + "x" + tex.getImage().getHeight() + " to " + nextWidth + "x" + nextHeight); } scaleToPot = true; } updateTexImageData(image, tex.getType(), unit, scaleToPot); } int texId = image.getId(); assert texId != -1; setupTextureParams(unit, tex); }