use of org.terasology.engine.rendering.opengl.FBO in project Terasology by MovingBlocks.
the class ModuleRendering method generateWithDimensions.
/**
*TODO UPDATE the javadoc, this method has been taken from abstractfbomanager during DAG Enhancement project
* Generates and returns an FBO as characterized by the FboConfig and the dimensions arguments.
*
* Notice that if the name of the FBO being generated matches the name of an FBO already stored
* by the manager, the latter will be overwritten. However, the GPU-side Frame Buffer associated
* with the overwritten FBO is not disposed by this method.
*
* As such, this method should be used only after the relevant checks are made and any
* pre-existing FBO with the same name as the new one is appropriately disposed.
*
* This method produces errors in the log in case the FBO generation process results in
* FBO.Status.INCOMPLETE or FBO.Status.UNEXPECTED.
*
* @param fboConfig an FboConfig object providing FBO configuration details.
* @param dimensions an FBO.Dimensions instance providing the dimensions of the FBO.
* @return an FBO instance
*/
protected FBO generateWithDimensions(FboConfig fboConfig, FBO.Dimensions dimensions) {
fboConfig.setDimensions(dimensions);
FBO fbo = FBO.create(fboConfig);
// the effects of using an incomplete FrameBuffer are. Throw an exception? Live with visual artifacts?
if (fbo.getStatus() == FBO.Status.INCOMPLETE) {
logger.error("FBO " + fboConfig.getName() + " is incomplete. Look earlier in the log for details.");
} else if (fbo.getStatus() == FBO.Status.UNEXPECTED) {
logger.error("FBO " + fboConfig.getName() + " has generated an unexpected status code. Look earlier in the log for details.");
}
return fbo;
}
use of org.terasology.engine.rendering.opengl.FBO in project Terasology by MovingBlocks.
the class ShadowMapResolutionDependentFbo method propertyChange.
/**
* Triggers the regeneration of the shadow map FBOs, if necessary.
*
* Once triggered this method checks if "dynamic shadows" are enabled.
* If dynamics shadows are enabled it obtains the new Shadow Map resolution from the event
* passed to the method and regenerates the shadow map FBOs.
*
* @param evt a PropertyChangeEvent, containing the shadow map resolution.
*/
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (renderingConfig.isDynamicShadows()) {
int shadowMapResFromSettings = (int) evt.getNewValue();
shadowMapResolution = new FBO.Dimensions(shadowMapResFromSettings, shadowMapResFromSettings);
for (Map.Entry<SimpleUri, FboConfig> entry : fboConfigs.entrySet()) {
SimpleUri fboName = entry.getKey();
FboConfig fboConfig = entry.getValue();
if (fboLookup.containsKey(fboName)) {
FBO fbo = fboLookup.get(fboName);
if (fbo != null) {
// TODO: validate if necessary
fbo.dispose();
}
}
FBO shadowMapResDependentFBO = generateWithDimensions(fboConfig, shadowMapResolution);
if (shadowMapResDependentFBO.getStatus() == FBO.Status.DISPOSED) {
logger.warn("Failed to generate ShadowMap FBO. Turning off shadows.");
renderingConfig.setDynamicShadows(false);
break;
}
fboLookup.put(fboName, shadowMapResDependentFBO);
}
}
}
use of org.terasology.engine.rendering.opengl.FBO in project Terasology by MovingBlocks.
the class AbstractNode method requiresFbo.
/**
* Used by inheriting classes to declare the need for a specific Frame Buffer Object and obtain it.
*
* The characteristics of the required FBO are described in the fboConfig provided in input.
* Within the context of the given fboManager an fboConfig uniquely identifies the FBO:
* if the FBO exists already it is returned, if it doesn't, the FBO is first created and then returned.
*
* If the fboManager already contains an FBO with the same fboUri but different characteristics from
* those described in the fboConfig object, an IllegalArgumentException is thrown.
*
* @param fboConfig an FboConfig object describing the required FBO.
* @param fboManager a BaseFboManager object from which to obtain the FBO.
* @return the requested FBO object, either newly created or a pre-existing one.
* @throws IllegalArgumentException if the fboUri in fboConfig already in use by FBO with different characteristics.
*/
protected FBO requiresFbo(FboConfig fboConfig, BaseFboManager fboManager) {
SimpleUri fboName = fboConfig.getName();
FBO fbo;
if (!fboUsages.containsKey(fboName)) {
fboUsages.put(fboName, fboManager);
} else {
logger.warn("FBO " + fboName + " is already requested.");
fbo = fboManager.get(fboName);
this.addInputFboConnection(inputConnections.size() + 1, fbo);
return fbo;
}
fbo = fboManager.request(fboConfig);
return fbo;
}
use of org.terasology.engine.rendering.opengl.FBO in project Terasology by MovingBlocks.
the class ModuleRendering method createBufferPair.
protected BufferPair createBufferPair(String primaryBufferName, String secondaryBufferName, ScalingFactors sharedBufferScale, FBO.Type sharedBufferType, FBO.Dimensions scale) {
FBO buffer1 = generateWithDimensions(new FboConfig(new SimpleUri(providingModule + ":fbo." + primaryBufferName), sharedBufferScale, sharedBufferType).useDepthBuffer().useNormalBuffer().useLightBuffer().useStencilBuffer(), scale);
FBO buffer2 = generateWithDimensions(new FboConfig(new SimpleUri(providingModule + ":fbo." + secondaryBufferName), sharedBufferScale, sharedBufferType).useDepthBuffer().useNormalBuffer().useLightBuffer().useStencilBuffer(), scale);
return new BufferPair(buffer1, buffer2);
}
use of org.terasology.engine.rendering.opengl.FBO in project Terasology by MovingBlocks.
the class WorldRendererImpl method render.
/**
* TODO: update javadocs This method triggers the execution of the rendering pipeline and, eventually, sends the
* output to the display or to a file, when grabbing a screenshot.
* <p>
* In this particular implementation this method can be called once per frame, when rendering to a standard display,
* or twice, each time with a different rendering stage, when rendering to the head mounted display.
* <p>
* PerformanceMonitor.startActivity/endActivity statements are used in this method and in those it executes, to
* provide statistics regarding the ongoing rendering and its individual steps (i.e. rendering shadows, reflections,
* 2D filters...).
*
* @param renderingStage "MONO" for standard rendering and "LEFT_EYE" or "RIGHT_EYE" for stereoscopic
* displays.
*/
@Override
public void render(RenderingStage renderingStage) {
preRenderUpdate(renderingStage);
// TODO: Add a method here to check wireframe configuration and regenerate "renderPipelineTask" accordingly.
// The following line re-establish OpenGL defaults, so that the nodes/tasks can rely on them.
// A place where Terasology overrides the defaults is LwjglGraphics.initOpenGLParams(), but
// there could be potentially other places, i.e. in the UI code. In the rendering engine we'd like
// to eventually rely on a default OpenGL state.
glDisable(GL_CULL_FACE);
FBO lastUpdatedGBuffer = displayResolutionDependentFbo.getGBufferPair().getLastUpdatedFbo();
glViewport(0, 0, lastUpdatedGBuffer.width(), lastUpdatedGBuffer.height());
renderPipelineTaskList.forEach(RenderPipelineTask::process);
// this line re-establish Terasology defaults, so that the rest of the application can rely on them.
LwjglGraphicsUtil.initOpenGLParams();
playerCamera.updatePrevViewProjectionMatrix();
}
Aggregations