fixed music selection page bug where after resize and metadata loading, application would crash
This commit is contained in:
parent
188608d40d
commit
8fd727e7d6
@ -16,7 +16,6 @@ public class MusicInfoController implements Disposable {
|
||||
private ExecutorService exec;
|
||||
private Array<MusicInfo> songInfoArray;
|
||||
private Preferences musicAnnotation;
|
||||
private boolean doneLoading;
|
||||
|
||||
public MusicInfoController(MusicList musicList) {
|
||||
this.musicList = musicList;
|
||||
@ -33,39 +32,33 @@ public class MusicInfoController implements Disposable {
|
||||
* Non-blocking, loads on separate thread.
|
||||
*/
|
||||
public void loadSongInfo() {
|
||||
doneLoading = false;
|
||||
for (int i = 0; i < songInfoArray.size; i++) {
|
||||
songInfoArray.get(i).dispose();
|
||||
}
|
||||
songInfoArray.clear();
|
||||
exec.submit(() -> {
|
||||
for (int i = 0; i < musicList.getTotal(); i++) {
|
||||
MusicInfo musicInfo = new MusicInfo(musicList.getMusicList().get(i), musicAnnotation);
|
||||
MusicInfo musicInfo = new MusicInfo(musicList.getMusicArray().get(i), musicAnnotation);
|
||||
musicInfo.loadInfo();
|
||||
songInfoArray.add(musicInfo);
|
||||
}
|
||||
doneLoading = true;
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return (songInfoArray.size == musicList.getMusicArray().size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
exec.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if loading song info is done.
|
||||
* @return
|
||||
*/
|
||||
public synchronized boolean isDoneLoading() {
|
||||
return doneLoading;
|
||||
}
|
||||
|
||||
public Array<MusicInfo> getSongInfoArray() {
|
||||
return songInfoArray;
|
||||
}
|
||||
|
||||
public MusicInfo getInfo(FileHandle filehandle) {
|
||||
return songInfoArray.get(musicList.getMusicList().indexOf(filehandle, true));
|
||||
return songInfoArray.get(musicList.getMusicArray().indexOf(filehandle, true));
|
||||
}
|
||||
}
|
||||
|
@ -13,14 +13,14 @@ import zero1hd.rhythmbullet.audio.MusicManager;
|
||||
import zero1hd.rhythmbullet.util.FileHandleAlphabeticalComparator;
|
||||
|
||||
public class MusicList extends Observable {
|
||||
private Array<FileHandle> musicList;
|
||||
private Array<FileHandle> musicArray;
|
||||
private String searchPath;
|
||||
private boolean searched;
|
||||
private FileHandleAlphabeticalComparator fhac;
|
||||
private ExecutorService exec;
|
||||
|
||||
public MusicList() {
|
||||
musicList = new Array<>();
|
||||
musicArray = new Array<>();
|
||||
fhac = new FileHandleAlphabeticalComparator();
|
||||
exec = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
@ -46,17 +46,17 @@ public class MusicList extends Observable {
|
||||
*/
|
||||
public void refresh(boolean notifyOnCompletion) {
|
||||
searched = false;
|
||||
musicList.clear();
|
||||
musicArray.clear();
|
||||
Gdx.app.debug("SongController", "Searching path: " + searchPath);
|
||||
if (Gdx.files.absolute(searchPath).exists() && Gdx.files.absolute(searchPath).isDirectory()) {
|
||||
musicList.addAll(recursiveMusicFileList(Gdx.files.absolute(searchPath)));
|
||||
musicArray.addAll(recursiveMusicFileList(Gdx.files.absolute(searchPath)));
|
||||
}
|
||||
if (!Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3").exists()) {
|
||||
Gdx.files.internal("music/Alan Walker - Spectre.mp3").copyTo(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
|
||||
}
|
||||
musicList.add(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
|
||||
musicArray.add(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
|
||||
setChanged();
|
||||
Sort.instance().sort(musicList, fhac);
|
||||
Sort.instance().sort(musicArray, fhac);
|
||||
searched = true;
|
||||
|
||||
if (notifyOnCompletion) {
|
||||
@ -101,20 +101,20 @@ public class MusicList extends Observable {
|
||||
|
||||
public MusicManager getMusicManagerFromIndex(int index) {
|
||||
if (!searched) Gdx.app.debug("SongList", "Warning, this list hasn't even searched yet...");
|
||||
return getAudioData(musicList.get(index));
|
||||
return getAudioData(musicArray.get(index));
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return musicList.size;
|
||||
return musicArray.size;
|
||||
}
|
||||
|
||||
public FileHandle getSongFileHandleFromIndex(int index) {
|
||||
if (!searched) Gdx.app.debug("SongList", "Warning, this list hasn't even searched yet...");
|
||||
return musicList.get(index);
|
||||
return musicArray.get(index);
|
||||
}
|
||||
|
||||
public Array<FileHandle> getMusicList() {
|
||||
return musicList;
|
||||
public Array<FileHandle> getMusicArray() {
|
||||
return musicArray;
|
||||
}
|
||||
|
||||
public boolean isSearched() {
|
||||
|
@ -194,7 +194,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
if (uiSongCount == mc.getMusicList().getTotal()) {
|
||||
selectMusicUI(mc.getCurrentMusicManager());
|
||||
}
|
||||
} else if (uiSongInfoCount < selectables.size && mic.isDoneLoading()) {
|
||||
} else if (uiSongInfoCount < selectables.size && mic.isDone()) {
|
||||
selectables.get(uiSongInfoCount).updateInfo(mic.getSongInfoArray().get(uiSongInfoCount));
|
||||
uiSongInfoCount++;
|
||||
if (uiSongInfoCount == selectables.size) {
|
||||
@ -267,7 +267,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
this.currentlySelected = currentlySelected;
|
||||
songSelectionTimer = 1f;
|
||||
|
||||
if (mic.isDoneLoading() && uiSongInfoCount == selectables.size) {
|
||||
if (mic.isDone() && uiSongInfoCount == selectables.size) {
|
||||
updateInformation();
|
||||
}
|
||||
}
|
||||
@ -314,7 +314,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
|
||||
private void playSelectedMusic() {
|
||||
if (currentlySelected.getMusicFile() != mc.getCurrentMusicManager().getMusicFile()) {
|
||||
int index = mc.getMusicList().getMusicList().indexOf(currentlySelected.getMusicFile(), true);
|
||||
int index = mc.getMusicList().getMusicArray().indexOf(currentlySelected.getMusicFile(), true);
|
||||
mc.setMusicByIndex(index);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import com.badlogic.gdx.ScreenAdapter;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
||||
@ -34,7 +34,6 @@ import zero1hd.rhythmbullet.util.AdvancedResizeScreen;
|
||||
|
||||
public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScreen {
|
||||
public Stage stage;
|
||||
private Texture background;
|
||||
private Vector3 cameraPosition;
|
||||
|
||||
private MainPage mainPage;
|
||||
@ -60,9 +59,8 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
||||
private TextureRegion fboRegion;
|
||||
private int fboSize;
|
||||
private int blurlvl;
|
||||
private SpriteBatch screenBatch;
|
||||
private Batch batch;
|
||||
private ScreenViewport screenViewport;
|
||||
private boolean shaderLoaded;
|
||||
|
||||
public MainMenuScreen(RhythmBullet core) {
|
||||
this.core = core;
|
||||
@ -77,21 +75,110 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
||||
mlc.setShuffle(true);
|
||||
|
||||
mic = new MusicInfoController(musicList);
|
||||
}
|
||||
|
||||
screenBatch = new SpriteBatch();
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
stage.act(delta);
|
||||
if (blurlvl > 0) {
|
||||
// Begin drawing a normal version of screen
|
||||
normalBuffer.begin();
|
||||
stage.getViewport().apply();
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
stage.draw();
|
||||
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());
|
||||
batch.setShader(brightFilterShader);
|
||||
batch.setProjectionMatrix(screenViewport.getCamera().combined);
|
||||
batch.begin(); //BATCH STARTS HERE
|
||||
batch.draw(fboRegion, 0, 0, stage.getWidth(), stage.getHeight());
|
||||
batch.flush();
|
||||
lightFilterBuffer.end();
|
||||
//
|
||||
for (int i = 0; i < blurlvl; i++) {
|
||||
// Horizontal gaussian blur
|
||||
hBlur.begin();
|
||||
if (i > 0) {
|
||||
fboRegion.setTexture(vBlur.getColorBufferTexture());
|
||||
} else {
|
||||
fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture());
|
||||
}
|
||||
batch.setShader(gaussianBlurShader);
|
||||
gaussianBlurShader.setUniformi("horizontal", 1);
|
||||
batch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
|
||||
batch.flush();
|
||||
hBlur.end();
|
||||
|
||||
// //Vertical gaussian blur
|
||||
vBlur.begin();
|
||||
fboRegion.setTexture(hBlur.getColorBufferTexture());
|
||||
batch.setShader(gaussianBlurShader);
|
||||
gaussianBlurShader.setUniformi("horizontal", 0);
|
||||
batch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
|
||||
batch.flush();
|
||||
vBlur.end();
|
||||
}
|
||||
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
batch.setShader(combineShader);
|
||||
fboRegion.setTexture(normalBuffer.getColorBufferTexture());
|
||||
batch.draw(fboRegion, 0f, 0f, fboSize, fboSize);
|
||||
batch.setShader(null);
|
||||
batch.end(); //STAGE BATCH ENDS HERE
|
||||
|
||||
} else {
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
if (stage.getCamera().position.x != cameraPosition.x || stage.getCamera().position.y != cameraPosition.y) {
|
||||
stage.getCamera().position.lerp(cameraPosition, delta*lerpAlpha);
|
||||
stage.getViewport().apply();
|
||||
}
|
||||
|
||||
super.render(delta);
|
||||
}
|
||||
@Override
|
||||
public void preAssetLoad() {
|
||||
stage.clear();
|
||||
mainPage.dispose();
|
||||
optionsPage.dispose();
|
||||
creditsPage.dispose();
|
||||
keybindPage.dispose();
|
||||
musicSelectionPage.dispose();
|
||||
|
||||
dismantleShaders();
|
||||
setBlurlvl(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postAssetLoad() {
|
||||
attemptLoadShaders();
|
||||
if (core.getPrefs().getBoolean("glow shader", true)) {
|
||||
setupShaders();
|
||||
|
||||
if (core.getPrefs().getBoolean("enhanced glow", false)) {
|
||||
setBlurlvl(1);
|
||||
} else {
|
||||
setBlurlvl(4);
|
||||
}
|
||||
}
|
||||
|
||||
mainPage = new MainPage(core, cameraPosition, mlc, this);
|
||||
mainPage.setPosition(0, 0);
|
||||
stage.addActor(mainPage);
|
||||
//End main menu
|
||||
|
||||
background = core.getAssetManager().get("backgrounds/mainBG.png", Texture.class);
|
||||
|
||||
|
||||
keybindPage = new KeybindOptionsPage(core.getDefaultSkin(), core.getAssetManager(), cameraPosition);
|
||||
keybindPage.setPosition(-1f*Gdx.graphics.getWidth(), -1f*Gdx.graphics.getHeight());
|
||||
stage.addActor(keybindPage);
|
||||
@ -137,11 +224,11 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
|
||||
mlc.getMusicList().deleteObservers();
|
||||
mlc.deleteObservers();
|
||||
mlc.addObserver(musicSelectionPage);
|
||||
mlc.addObserver(mainPage);
|
||||
mlc.getMusicList().addObserver(mainPage);
|
||||
mlc.getMusicList().addObserver(optionsPage);
|
||||
mlc.addObserver(musicSelectionPage);
|
||||
|
||||
if (mlc.getMusicList().isSearched() && mlc.getCurrentMusicManager() != null) {
|
||||
MusicManager mManager = mlc.getCurrentMusicManager();
|
||||
@ -150,104 +237,6 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
Gdx.gl.glClearColor(0.22f, 0.22f, 0.22f, 1f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
stage.act(delta);
|
||||
|
||||
if (blurlvl > 0) {
|
||||
// Begin drawing a normal version of screen
|
||||
normalBuffer.begin();
|
||||
stage.getViewport().apply();
|
||||
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
draw();
|
||||
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(); //BATCH STARTS HERE
|
||||
//TODO Do shader version of background for main menu.
|
||||
|
||||
screenBatch.draw(fboRegion, 0, 0, stage.getWidth(), stage.getHeight());
|
||||
screenBatch.flush();
|
||||
lightFilterBuffer.end();
|
||||
//
|
||||
for (int i = 0; i < blurlvl; 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, stage.getWidth(), stage.getHeight());
|
||||
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, stage.getWidth(), stage.getHeight());
|
||||
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, fboSize, fboSize);
|
||||
screenBatch.setShader(null);
|
||||
screenBatch.end(); //BATCH ENDS HERE
|
||||
|
||||
} else {
|
||||
draw();
|
||||
}
|
||||
|
||||
//move camera
|
||||
if (stage.getCamera().position.x != cameraPosition.x || stage.getCamera().position.y != cameraPosition.y) {
|
||||
stage.getCamera().position.lerp(cameraPosition, delta*lerpAlpha);
|
||||
stage.getViewport().apply();
|
||||
}
|
||||
|
||||
super.render(delta);
|
||||
}
|
||||
|
||||
private void draw() {
|
||||
screenBatch.begin();
|
||||
screenBatch.draw(background, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
screenBatch.end();
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preAssetLoad() {
|
||||
mlc.getMusicList().deleteObservers();
|
||||
mlc.deleteObservers();
|
||||
|
||||
stage.clear();
|
||||
mainPage.dispose();
|
||||
screenBatch.dispose();
|
||||
optionsPage.dispose();
|
||||
creditsPage.dispose();
|
||||
keybindPage.dispose();
|
||||
musicSelectionPage.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
@ -280,23 +269,75 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
||||
@Override
|
||||
public void dispose() {
|
||||
stage.dispose();
|
||||
unloadShaders();
|
||||
dismantleShaders();
|
||||
mic.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
private void calcLerpAlpha(int width) {
|
||||
if (width <= 3835) {
|
||||
lerpAlpha = 5.0f;
|
||||
} else {
|
||||
lerpAlpha = 5.5f;
|
||||
public void setupShaders() {
|
||||
Gdx.app.debug("Shader", "Loading glow shaders.");
|
||||
batch = new SpriteBatch();
|
||||
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());
|
||||
}
|
||||
|
||||
public void unloadShaders() {
|
||||
Gdx.app.debug("MainMenu", "shader being unloaded.");
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
if (Gdx.graphics.getWidth() < 1024) {
|
||||
fboSize = 1024;
|
||||
} else if (Gdx.graphics.getWidth() < 2048) {
|
||||
fboSize = 2048;
|
||||
} else {
|
||||
fboSize = 4096;
|
||||
}
|
||||
|
||||
lightFilterBuffer = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
|
||||
normalBuffer = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false);
|
||||
hBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
|
||||
vBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, 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 dismantleShaders() {
|
||||
if (core.getPrefs().getBoolean("glow shader")) {
|
||||
if (shaderLoaded) {
|
||||
brightFilterShader.dispose();
|
||||
combineShader.dispose();
|
||||
gaussianBlurShader.dispose();
|
||||
@ -305,7 +346,6 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
||||
vBlur.dispose();
|
||||
hBlur.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
brightFilterShader = null;
|
||||
combineShader = null;
|
||||
@ -315,16 +355,11 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
||||
vBlur = null;
|
||||
hBlur = null;
|
||||
|
||||
shaderLoaded = false;
|
||||
setBlurlvl(0);
|
||||
}
|
||||
|
||||
public void setBlurlvl(int blurlvl) {
|
||||
this.blurlvl = blurlvl;
|
||||
if (blurlvl > 0) {
|
||||
attemptLoadShaders();
|
||||
} else {
|
||||
unloadShaders();
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 getCameraPosition() {
|
||||
@ -351,78 +386,13 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
||||
return optionsPage;
|
||||
}
|
||||
|
||||
public int attemptLoadShaders() {
|
||||
|
||||
Gdx.app.debug("MainMenu", "Attempting to load shaders.");
|
||||
if (core.getPrefs().getBoolean("glow shader", true) && !shaderLoaded) {
|
||||
if (core.getPrefs().getBoolean("enhanced glow", false)) {
|
||||
blurlvl = 5;
|
||||
private void calcLerpAlpha(int width) {
|
||||
if (width <= 3835) {
|
||||
lerpAlpha = 5.0f;
|
||||
} else {
|
||||
blurlvl = 1;
|
||||
lerpAlpha = 5.5f;
|
||||
}
|
||||
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());
|
||||
if (brightFilterShader.getLog().length() != 0) {
|
||||
Gdx.app.error("Shader", brightFilterShader.getLog());
|
||||
}
|
||||
setBlurlvl(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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());
|
||||
if (gaussianBlurShader.getLog().length() != 0) {
|
||||
Gdx.app.error("Shader", gaussianBlurShader.getLog());
|
||||
}
|
||||
setBlurlvl(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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());
|
||||
if (combineShader.getLog().length() != 0) {
|
||||
Gdx.app.error("Shader", combineShader.getLog());
|
||||
}
|
||||
setBlurlvl(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Gdx.graphics.getWidth() < 1024) {
|
||||
fboSize = 1024;
|
||||
} else if (Gdx.graphics.getWidth() < 2048) {
|
||||
fboSize = 2048;
|
||||
} else {
|
||||
fboSize = 4096;
|
||||
}
|
||||
|
||||
lightFilterBuffer = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
|
||||
normalBuffer = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false);
|
||||
hBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
|
||||
vBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, 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;
|
||||
shaderLoaded = true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user