restructured way of handling the relationship between screens and pages

This commit is contained in:
2018-07-26 13:17:35 -05:00
parent 7dff918802
commit 590cb39902
22 changed files with 650 additions and 1167 deletions

View File

@@ -104,7 +104,7 @@ public class RhythmBullet extends Game {
if (skin != null) skin.dispose();
skin = new Skin();
skinAtlas = assetManager.get("uiskin.atlas", TextureAtlas.class);
getSkinSkin().addRegions(skinAtlas);
getSkin().addRegions(skinAtlas);
assetPack.generateFonts(skin);
assetPack.setupSkin(skin);
@@ -181,7 +181,7 @@ public class RhythmBullet extends Game {
return assetManager;
}
public Skin getSkinSkin() {
public Skin getSkin() {
return skin;
}
@@ -194,7 +194,7 @@ public class RhythmBullet extends Game {
Gdx.app.debug("Core", "disposing...");
try {
skinAtlas.dispose();
getSkinSkin().dispose();
getSkin().dispose();
assetManager.dispose();
getScreen().dispose();
assetPack.dispose();

View File

@@ -0,0 +1,160 @@
package zero1hd.rhythmbullet.graphics.shaders;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
public class BloomShader implements Disposable {
private int bloomLevel;
private ShaderProgram gaussianBlurShader;
private ShaderProgram brightFilterShader;
private ShaderProgram combineShader;
private FrameBuffer lightFilterBuffer;
private FrameBuffer normalBuffer;
private FrameBuffer hBlur, vBlur;
private TextureRegion fboRegion;
private Batch screenBatch;
private ScreenViewport screenViewport;
public BloomShader(Batch batch) {
this.screenBatch = batch;
Gdx.app.debug("Shader", "Loading glow shaders.");
screenViewport = new ScreenViewport();
screenViewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
((OrthographicCamera) screenViewport.getCamera()).setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.app.debug("Shader", "using glow shader");
brightFilterShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/bright_filter.fsh"));
if (!brightFilterShader.isCompiled()) {
Gdx.app.error("Shader failed to compile", brightFilterShader.getLog());
System.exit(0);
}
if (brightFilterShader.getLog().length() != 0) {
Gdx.app.error("Shader", brightFilterShader.getLog());
}
gaussianBlurShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/gaussian_blur.fsh"));
if (!gaussianBlurShader.isCompiled()) {
Gdx.app.error("Shader failed to compile", gaussianBlurShader.getLog());
System.exit(0);
}
if (gaussianBlurShader.getLog().length() != 0) {
Gdx.app.error("Shader", gaussianBlurShader.getLog());
}
combineShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/combine.fsh"));
if (!combineShader.isCompiled()) {
Gdx.app.error("Shader failed to compile", combineShader.getLog());
System.exit(0);
}
if (combineShader.getLog().length() != 0) {
Gdx.app.error("Shader", combineShader.getLog());
}
lightFilterBuffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
normalBuffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
hBlur = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
vBlur = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
fboRegion = new TextureRegion(normalBuffer.getColorBufferTexture());
fboRegion.flip(false, true);
combineShader.begin();
combineShader.setUniformi("u_texture1", 1);
combineShader.end();
vBlur.getColorBufferTexture().bind(1);
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);
ShaderProgram.pedantic = false;
}
public void begin() {
// Begin drawing a normal version of screen
normalBuffer.begin();
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
}
public void end(float width, float height) {
normalBuffer.end();
// BEGINNING NORMAL SCREEN RENDER
screenViewport.apply();
// Begin light filtering
lightFilterBuffer.begin();
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
fboRegion.setTexture(normalBuffer.getColorBufferTexture());
screenBatch.setShader(brightFilterShader);
screenBatch.setProjectionMatrix(screenViewport.getCamera().combined);
screenBatch.begin(); //SCREEN BATCH STARTS HERE
screenBatch.draw(fboRegion, 0, 0, width, height);
screenBatch.flush();
lightFilterBuffer.end();
for (int i = 0; i <= bloomLevel; i++) {
// Horizontal gaussian blur
hBlur.begin();
if (i > 0) {
fboRegion.setTexture(vBlur.getColorBufferTexture());
} else {
fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture());
}
screenBatch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 1);
screenBatch.draw(fboRegion, 0f, 0f, width, height);
screenBatch.flush();
hBlur.end();
// //Vertical gaussian blur
vBlur.begin();
fboRegion.setTexture(hBlur.getColorBufferTexture());
screenBatch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 0);
screenBatch.draw(fboRegion, 0f, 0f, width, height);
screenBatch.flush();
vBlur.end();
}
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
screenBatch.setShader(combineShader);
fboRegion.setTexture(normalBuffer.getColorBufferTexture());
screenBatch.draw(fboRegion, 0f, 0f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
screenBatch.setShader(null);
screenBatch.end(); //STAGE BATCH ENDS HERE
}
public void setBloomLevel(int bloomLevel) {
this.bloomLevel = bloomLevel;
}
@Override
public void dispose() {
brightFilterShader.dispose();
combineShader.dispose();
gaussianBlurShader.dispose();
normalBuffer.dispose();
lightFilterBuffer.dispose();
vBlur.dispose();
hBlur.dispose();
brightFilterShader = null;
combineShader = null;
gaussianBlurShader = null;
normalBuffer = null;
lightFilterBuffer = null;
vBlur = null;
hBlur = null;
}
}