private final int bindTextureWeighted (final GLTexture texture) { int result = -1; int weight = weights[0]; int windex = 0; for (int i = 0; i < count; i++) { if (textures[i] == texture) { result = i; weights[i] += reuseWeight; } else if (weights[i] < 0 || --weights[i] < weight) { weight = weights[i]; windex = i; } } if (result < 0) { textures[windex] = texture; weights[windex] = 100; texture.bind(offset + (result = windex)); } else reused = true; return result; }
public boolean hasPendingChanges () { State pending = this.pending; State current = this.current; if (pending.depthMasking != current.depthMasking) return true; if (pending.depthTesting != current.depthTesting) return true; if (pending.depthTesting && pending.depthFunc != current.depthFunc) return true; if (pending.blending != current.blending) return true; if (pending.blending) { if (pending.blendSrcFuncColor != current.blendSrcFuncColor || pending.blendDstFuncColor != current.blendDstFuncColor || pending.blendSrcFuncAlpha != current.blendSrcFuncAlpha || pending.blendDstFuncAlpha != current.blendDstFuncAlpha) return true; if (pending.blendEquationColor != current.blendEquationColor || pending.blendEquationAlpha != current.blendEquationAlpha) return true; } IntMap<GLTexture> actualTextureUnits = current.textureUnits; for (IntMap.Entry<GLTexture> entry : pending.textureUnits) { if (actualTextureUnits.get(entry.key) != entry.value) return true; } return false; }
/** Sets the texture to be bound to the given texture unit. * @return Whether the pending texture for the unit was changed. */ public boolean setTextureUnit (GLTexture texture, int unit) { if (pending.textureUnits.get(unit) != texture) { if (texture == null) pending.textureUnits.remove(unit); else pending.textureUnits.put(unit, texture); return true; } return false; }
@Override public void bind(ShaderProgram shader, LevelEnv env, RenderContext context, Camera camera) { GLTexture texture = env.water.getWaterDisplacementTexture(); if (texture != null) { shader.setUniformi(UNIFORM_DUDV_TEXTURE, context.textureBinder.bind(texture)); } }
@Override public void bind(ShaderProgram shader, LevelEnv env, RenderContext context, Camera camera) { GLTexture terrainTexture = ForgE.blocks.getTerrainTexture(); if (terrainTexture != null) { shader.setUniformi(UNIFORM_DIFFUSE_TEXTURE, context.textureBinder.bind(terrainTexture)); } }
@Override public void bind(ShaderProgram shader, LevelEnv env, RenderContext context, Camera camera) { GLTexture normalTexture = env.water.getWaterNormalMapATexture(); if (normalTexture != null) { shader.setUniformi(UNIFORM_NORMAL_A_TEXTURE, context.textureBinder.bind(normalTexture)); } normalTexture = env.water.getWaterNormalMapBTexture(); if (normalTexture != null) { shader.setUniformi(UNIFORM_NORMAL_B_TEXTURE, context.textureBinder.bind(normalTexture)); } }
public GLTexture getWaterDisplacementTexture() { if (waterDisplacementTexture == null && getWaterDisplacementTextureAsset() != null) { waterDisplacementTexture = getWaterDisplacementTextureAsset().get(); waterDisplacementTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); } return waterDisplacementTexture; }
public GLTexture getWaterNormalMapATexture() { if (waterNormalATexture == null && getWaterNormalMapATextureAsset() != null) { waterNormalATexture = getWaterNormalMapATextureAsset().get(); waterNormalATexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); } return waterNormalATexture; }
public GLTexture getWaterNormalMapBTexture() { if (waterNormalBTexture == null && getWaterNormalMapBTextureAsset() != null) { waterNormalBTexture = getWaterNormalMapBTextureAsset().get(); waterNormalBTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); } return waterNormalBTexture; }
public DefaultTextureBinder (final int method, final int offset, int count, final int reuseWeight) { final int max = Math.min(getMaxTextureUnits(), MAX_GLES_UNITS); if (count < 0) count = max - offset; if (offset < 0 || count < 0 || (offset + count) > max || reuseWeight < 1) throw new GdxRuntimeException("Illegal arguments"); this.method = method; this.offset = offset; this.count = count; this.textures = new GLTexture[count]; this.reuseWeight = reuseWeight; this.weights = (method == WEIGHTED) ? new int[count] : null; }
private final int bindTexture (final TextureDescriptor textureDesc, final boolean rebind) { final int idx, result; final GLTexture texture = textureDesc.texture; reused = false; switch (method) { case ROUNDROBIN: result = offset + (idx = bindTextureRoundRobin(texture)); break; case WEIGHTED: result = offset + (idx = bindTextureWeighted(texture)); break; default: return -1; } if (reused) { reuseCount++; if (rebind) texture.bind(result); else Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0 + result); } else bindCount++; texture.unsafeSetWrap(textureDesc.uWrap, textureDesc.vWrap); texture.unsafeSetFilter(textureDesc.minFilter, textureDesc.magFilter); return result; }
private final int bindTextureRoundRobin (final GLTexture texture) { for (int i = 0; i < count; i++) { final int idx = (currentTexture + i) % count; if (textures[idx] == texture) { reused = true; return idx; } } currentTexture = (currentTexture + 1) % count; textures[currentTexture] = texture; texture.bind(offset + currentTexture); return currentTexture; }
/** Applies the pending state changes and texture bindings to GL. This must be called in between {@link #begin()} and * {@link #end()}. */ public void executeChanges () { State pending = this.pending; State current = this.current; if (pending.depthMasking != current.depthMasking) { Gdx.gl.glDepthMask(pending.depthMasking); current.depthMasking = pending.depthMasking; } if (pending.depthTesting != current.depthTesting) { if (pending.depthTesting) Gdx.gl.glEnable(GL20.GL_DEPTH_TEST); else Gdx.gl.glDisable(GL20.GL_DEPTH_TEST); current.depthTesting = pending.depthTesting; } if (pending.depthTesting) { if (pending.depthFunc != current.depthFunc) { Gdx.gl.glDepthFunc(pending.depthFunc); current.depthFunc = pending.depthFunc; } if (pending.depthRangeNear != current.depthRangeNear || pending.depthRangeFar != current.depthRangeFar) { Gdx.gl.glDepthRangef(pending.depthRangeNear, pending.depthRangeFar); current.depthRangeNear = pending.depthRangeNear; current.depthRangeFar = pending.depthRangeFar; } } if (pending.blending != current.blending) { if (pending.blending) Gdx.gl.glEnable(GL20.GL_BLEND); else Gdx.gl.glDisable(GL20.GL_BLEND); current.blending = pending.blending; } if (pending.blending) { if (pending.blendSrcFuncColor != current.blendSrcFuncColor || pending.blendDstFuncColor != current.blendDstFuncColor || pending.blendSrcFuncAlpha != current.blendSrcFuncAlpha || pending.blendDstFuncAlpha != current.blendDstFuncAlpha) { if (pending.blendSrcFuncColor == pending.blendSrcFuncAlpha && pending.blendDstFuncColor == pending.blendDstFuncAlpha) { Gdx.gl.glBlendFunc(pending.blendSrcFuncColor, pending.blendDstFuncColor); } else { Gdx.gl.glBlendFuncSeparate(pending.blendSrcFuncColor, pending.blendDstFuncColor, pending.blendSrcFuncAlpha, pending.blendDstFuncAlpha); } current.blendSrcFuncColor = pending.blendSrcFuncColor; current.blendDstFuncColor = pending.blendDstFuncColor; current.blendSrcFuncAlpha = pending.blendSrcFuncAlpha; current.blendDstFuncAlpha = pending.blendDstFuncAlpha; } if (pending.blendEquationColor != current.blendEquationColor || pending.blendEquationAlpha != current.blendEquationAlpha) { if (pending.blendEquationColor == pending.blendEquationAlpha) Gdx.gl.glBlendEquation(pending.blendEquationColor); else Gdx.gl.glBlendEquationSeparate(pending.blendEquationColor, pending.blendEquationAlpha); } } IntMap<GLTexture> currentTextureUnits = current.textureUnits; for (IntMap.Entry<GLTexture> entry : pending.textureUnits) { if (currentTextureUnits.get(entry.key) != entry.value) { entry.value.bind(entry.key); currentTextureUnits.put(entry.key, entry.value); } } }
protected Quad () { textures = new GLTexture[getNumberOfTextures()]; regions = new Region2D[getNumberOfTextures()]; for (int i = 0; i < regions.length; i++) regions[i] = new Region2D(); }
public GLTexture getWindDisplacementTexture() { if (windDisplacementTexture == null) { windDisplacementTexture = windDisplacementTextureAsset.get(); } return windDisplacementTexture; }
public GLTexture getTerrainTexture() { loadAtlasAndUvsIfNull(); return textureAtlas.getTextures().first(); }
@Override public void consumeCustomData (int target) { for(int i=0; i < mips.length; ++i){ GLTexture.uploadImageData(target, mips[i], i); } }
public final boolean set (final int uniform, final GLTexture texture) { if (locations[uniform] < 0) return false; program.setUniformi(locations[uniform], context.textureBinder.bind(texture)); return true; }
@Override public final int bind (final GLTexture texture) { tempDesc.set(texture, null, null, null, null); return bindTexture(tempDesc, false); }
public void setColorTexture(GLTexture colorTexture) { this.colorTexture = colorTexture; }
public void setOutlineTexture(GLTexture outlineTexture) { this.outlineTexture = outlineTexture; }
public void setDiffuseTexture(GLTexture diffuseTexture) { this.diffuseTexture = diffuseTexture; }
public GLTexture getBufferedTexture() { return fbo.getColorBufferTexture(); }
/** Sets the UV region of the most recently applied texture, using texel units. This must be called after a Texture or * TextureRegion has been set with {@link #texture(GLTexture)} or {@link #textureRegion(TextureRegion)}. Note that * TextureRegions have a Y-down coordinate system for UVs. * <p> * This method must not be called in a Batchable that supports zero textures. * @param x The left side of the region. * @param y The top side of the region. * @param width The width of the region. May be negative to flip the region in place. * @param height The height of the region. May be negative to flip the region in place. * @return This object for chaining. */ public Quad regionTexels (int x, int y, int width, int height) { GLTexture texture = textures[regionIndex]; float invTexWidth = 1f / texture.getWidth(); float invTexHeight = 1f / texture.getHeight(); return region(x * invTexWidth, y * invTexHeight, (x + width) * invTexWidth, (y + height) * invTexHeight); }
/** Binds the texture to an available unit. * @param texture the {@link Texture} * @return the unit the texture was bound to */ public int bind (GLTexture texture);