use of io.xol.chunkstories.renderer.opengl.shader.ShaderGL in project chunkstories by Hugobros3.
the class ShadersStore method loadShader.
boolean loadShader(String name) {
ShaderGL subject = new ShaderGL(clientContent.modsManager(), name);
loadedShaders.put(name, subject);
return subject.isLoadedCorrectly();
}
use of io.xol.chunkstories.renderer.opengl.shader.ShaderGL 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.renderer.opengl.shader.ShaderGL in project chunkstories by Hugobros3.
the class AttributesConfigurationImplementation method setup.
public void setup(RenderingInterface renderingInterface) {
ShaderGL shaderProgram = (ShaderGL) renderingInterface.currentShader();
Set<Integer> unusedAttributes = enabledVertexAttributes;
enabledVertexAttributes = new HashSet<Integer>(enabledVertexAttributes);
for (Entry<String, AttributeSource> e : attributes.entrySet()) {
String attributeName = e.getKey();
AttributeSource attributeSource = e.getValue();
int attributeLocation = shaderProgram.getVertexAttributeLocation(attributeName);
if (attributeLocation == -1)
continue;
unusedAttributes.remove(attributeLocation);
// Enable only when it wasn't
if (enabledVertexAttributes.add(attributeLocation))
glEnableVertexAttribArray(attributeLocation);
attributeSource.setup(attributeLocation);
}
// Disable and forget about unused ones
for (int unused : unusedAttributes) {
glDisableVertexAttribArray(unused);
enabledVertexAttributes.remove(unused);
}
}
Aggregations