use of io.xol.chunkstories.api.rendering.textures.Texture in project chunkstories by Hugobros3.
the class TextureGL method destroyPendingTextureObjects.
private static int destroyPendingTextureObjects() {
int destroyedVerticesObjects = 0;
synchronized (objectsToDestroy) {
Iterator<TextureGL> i = objectsToDestroy.iterator();
while (i.hasNext()) {
Texture object = i.next();
if (object.destroy())
destroyedVerticesObjects++;
i.remove();
}
}
Iterator<Entry<Integer, WeakReference<TextureGL>>> i = allocatedIds.entrySet().iterator();
while (i.hasNext()) {
Entry<Integer, WeakReference<TextureGL>> entry = i.next();
int id = entry.getKey();
WeakReference<TextureGL> weakReference = entry.getValue();
Texture texture = weakReference.get();
if (texture == null) {
logger.info("Disallocated orphan openGL texture ID " + id);
glDeleteTextures(id);
destroyedVerticesObjects++;
i.remove();
}
}
return destroyedVerticesObjects;
}
use of io.xol.chunkstories.api.rendering.textures.Texture in project chunkstories by Hugobros3.
the class TextureGL method getTotalVramUsage.
public static long getTotalVramUsage() {
long vram = 0;
// Iterates over every instance reference, removes null ones and add up valid ones
Iterator<WeakReference<TextureGL>> i = allTextureObjects.iterator();
while (i.hasNext()) {
WeakReference<TextureGL> reference = i.next();
Texture object = reference.get();
if (object != null)
vram += object.getVramUsage();
else
i.remove();
}
return vram;
}
use of io.xol.chunkstories.api.rendering.textures.Texture in project chunkstories by Hugobros3.
the class TexturingConfigurationImplementation method setup.
/**
* Setups the required texturing units and links the shaders uniforms to them
*/
public void setup(RenderingInterface renderingInterface) throws NotEnoughtTextureUnitsException {
ShaderGL shaderProgram = (ShaderGL) renderingInterface.currentShader();
// Drop the older bound textures when a new shader is used
if (lastShaderConfigured != shaderProgram) {
alreadyBound.clear();
this.resetBoundTextures();
} else {
// Go through the already bound textures
Iterator<Entry<Texture, Integer>> i = alreadyBound.entrySet().iterator();
while (i.hasNext()) {
Entry<Texture, Integer> e = i.next();
Texture texture = e.getKey();
// If one texture is no longer used, remove it
if (!allTextures.values().contains(texture)) {
i.remove();
boundTextures[e.getValue()] = null;
}
}
}
// For each sampler defined in the shader we will try to bind the necessary texture
for (Entry<String, SamplerType> e : shaderProgram.samplers().entrySet()) {
String samplerName = e.getKey();
// System.out.println("figuring out texture for"+samplerName);
Texture texture = allTextures.get(samplerName);
if (// No texture or the wrong type supplied ? No worries
texture == null || texture.getSamplerType() != e.getValue())
texture = defaultTextures[e.getValue().ordinal()];
// System.out.println(texture);
int alreadyBoundTextureUnit = alreadyBound.getOrDefault(texture, -1);
if (alreadyBoundTextureUnit == -1) {
int freeTextureUnit = findFreeTextureUnit();
this.selectTextureUnit(freeTextureUnit);
texture.bind();
alreadyBound.put(texture, freeTextureUnit);
boundTextures[freeTextureUnit] = texture;
int uniform = shaderProgram.getUniformLocation(samplerName);
if (uniform == -1)
continue;
glUniform1i(uniform, freeTextureUnit);
// if(shaderProgram.getShaderName().contains("postprocess"))
// System.out.println("bound " + samplerName + " to " + freeTextureUnit + " ("+uniform+") :" + texture);
} else {
glUniform1i(shaderProgram.getUniformLocation(samplerName), alreadyBoundTextureUnit);
}
}
lastShaderConfigured = shaderProgram;
}
use of io.xol.chunkstories.api.rendering.textures.Texture in project chunkstories by Hugobros3.
the class WorldRendererImplementation method blitFinalImage.
public void blitFinalImage(RenderingInterface renderingContext, boolean hideGui) {
Texture finalBuffer = this.renderingGraph.getRenderPass("final").resolvedOutputs.get("finalBuffer");
if (finalBuffer != null && finalBuffer instanceof Texture2D) {
final Texture2D finalTexture = (Texture2D) (finalBuffer);
// We render to the screen.
renderingContext.getRenderTargetManager().setConfiguration(null);
renderingContext.setDepthTestMode(DepthTestMode.DISABLED);
renderingContext.setBlendMode(BlendMode.DISABLED);
renderingContext.useShader("blit");
renderingContext.bindTexture2D("diffuseTexture", finalTexture);
renderingContext.drawFSQuad();
if (!hideGui) {
world.entitiesLock.readLock().lock();
Iterator<Entity> ei = world.getAllLoadedEntities();
Entity e;
while (ei.hasNext()) {
e = ei.next();
if (e instanceof EntityOverlay) {
((EntityOverlay) e).drawEntityOverlay(renderingContext);
}
}
world.entitiesLock.readLock().unlock();
}
}
}
use of io.xol.chunkstories.api.rendering.textures.Texture in project chunkstories by Hugobros3.
the class RenderingGraph method resolveInputs.
/**
* Passes the output buffers of the early passes to the inputs of the later ones
*/
private void resolveInputs() {
if (executionOrder != null) {
for (int i = 0; i < executionOrder.length; i++) {
RenderPass pass = executionOrder[i];
Map<String, Texture> inputs = new HashMap<>();
// For each buffer we depend on
for (String requirement : pass.requires) {
// System.out.println("resolving requirement "+requirement+" for pass "+pass.name);
// parse pass and buffer name
String[] s = requirement.split("\\.");
String requiredPassName = s[0];
String requiredBufferName = s.length > 0 ? s[1] : "invalid";
boolean forward = requiredBufferName.endsWith("!");
requiredBufferName = requiredBufferName.replace("!", "");
// System.out.println(requiredPassName+"."+requiredBufferName+" forward:"+forward);
RenderPass requiredPass = this.getRenderPass(requiredPassName);
// assumes all previous passes were resolved ok
Texture requiredBuffer = requiredPass == null ? null : requiredPass.resolvedOutputs.get(requiredBufferName);
if (forward) {
// System.out.println("auto-forwarding buffer:"+requiredBufferName);
pass.resolvedOutputs.put(requiredBufferName, requiredBuffer);
}
// return it the buffer he asked under multiple names
inputs.put(requiredPassName + "." + requiredBufferName, requiredBuffer);
inputs.put(requiredBufferName, requiredBuffer);
// may alias !
inputs.put(requirement, requiredBuffer);
}
// notify the pass we found it's buffers
pass.resolvedInputs.clear();
pass.resolvedInputs.putAll(inputs);
pass.onResolvedInputs();
}
}
}
Aggregations