Merge pull request #102 from Bigpet/slidershutdown
Fullscreen resizing fix (fixes #101)
This commit is contained in:
commit
b6a99f8bdd
|
@ -23,6 +23,7 @@ import itdelatrisu.opsu.beatmap.Beatmap;
|
||||||
import itdelatrisu.opsu.beatmap.BeatmapSetList;
|
import itdelatrisu.opsu.beatmap.BeatmapSetList;
|
||||||
import itdelatrisu.opsu.downloads.DownloadList;
|
import itdelatrisu.opsu.downloads.DownloadList;
|
||||||
import itdelatrisu.opsu.downloads.Updater;
|
import itdelatrisu.opsu.downloads.Updater;
|
||||||
|
import itdelatrisu.opsu.render.CurveRenderState;
|
||||||
import itdelatrisu.opsu.ui.UI;
|
import itdelatrisu.opsu.ui.UI;
|
||||||
|
|
||||||
import org.lwjgl.opengl.Display;
|
import org.lwjgl.opengl.Display;
|
||||||
|
@ -132,6 +133,9 @@ public class Container extends AppGameContainer {
|
||||||
// reset BeatmapSetList data
|
// reset BeatmapSetList data
|
||||||
if (BeatmapSetList.get() != null)
|
if (BeatmapSetList.get() != null)
|
||||||
BeatmapSetList.get().reset();
|
BeatmapSetList.get().reset();
|
||||||
|
|
||||||
|
// delete OpenGL objects involved in the Curve rendering
|
||||||
|
CurveRenderState.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -76,6 +76,17 @@ public class CurveRenderState {
|
||||||
FrameBufferCache.init(width, height);
|
FrameBufferCache.init(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undo the static state. Static state setup caused by calls to
|
||||||
|
* {@link #draw(org.newdawn.slick.Color, org.newdawn.slick.Color, itdelatrisu.opsu.objects.curves.Vec2f[])}
|
||||||
|
* are undone.
|
||||||
|
*/
|
||||||
|
public static void shutdown()
|
||||||
|
{
|
||||||
|
staticState.shutdown();
|
||||||
|
FrameBufferCache.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an object to hold the render state that's necessary to draw a curve.
|
* Creates an object to hold the render state that's necessary to draw a curve.
|
||||||
* @param hitObject the HitObject that represents this curve, just used as a unique ID
|
* @param hitObject the HitObject that represents this curve, just used as a unique ID
|
||||||
|
@ -138,7 +149,7 @@ public class CurveRenderState {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Discard the cache.
|
* Discard the cache mapping for this curve object
|
||||||
*/
|
*/
|
||||||
public void discardCache() {
|
public void discardCache() {
|
||||||
fbo = null;
|
fbo = null;
|
||||||
|
@ -440,6 +451,8 @@ public class CurveRenderState {
|
||||||
String error = GL20.glGetProgramInfoLog(program, 1024);
|
String error = GL20.glGetProgramInfoLog(program, 1024);
|
||||||
Log.error("Program linking failed.", new Exception(error));
|
Log.error("Program linking failed.", new Exception(error));
|
||||||
}
|
}
|
||||||
|
GL20.glDeleteShader(vtxShdr);
|
||||||
|
GL20.glDeleteShader(frgShdr);
|
||||||
attribLoc = GL20.glGetAttribLocation(program, "in_position");
|
attribLoc = GL20.glGetAttribLocation(program, "in_position");
|
||||||
texCoordLoc = GL20.glGetAttribLocation(program, "in_tex_coord");
|
texCoordLoc = GL20.glGetAttribLocation(program, "in_tex_coord");
|
||||||
texLoc = GL20.glGetUniformLocation(program, "tex");
|
texLoc = GL20.glGetUniformLocation(program, "tex");
|
||||||
|
@ -447,5 +460,28 @@ public class CurveRenderState {
|
||||||
colBorderLoc = GL20.glGetUniformLocation(program, "col_border");
|
colBorderLoc = GL20.glGetUniformLocation(program, "col_border");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleanup any OpenGL objects that may have been initialized.
|
||||||
|
*/
|
||||||
|
private void shutdown()
|
||||||
|
{
|
||||||
|
if(gradientTexture != 0)
|
||||||
|
{
|
||||||
|
GL11.glDeleteTextures(gradientTexture);
|
||||||
|
gradientTexture = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(program != 0)
|
||||||
|
{
|
||||||
|
GL20.glDeleteProgram(program);
|
||||||
|
program = 0;
|
||||||
|
attribLoc = 0;
|
||||||
|
texCoordLoc = 0;
|
||||||
|
colLoc = 0;
|
||||||
|
colBorderLoc = 0;
|
||||||
|
texLoc = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,6 +122,23 @@ public class FrameBufferCache {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the cache pool of Framebuffers.
|
||||||
|
* If there were any previous Framebuffers in the cache delete them
|
||||||
|
* this is necessary for cases when the game gets re-started with a
|
||||||
|
* different resolution without closing the process
|
||||||
|
*/
|
||||||
|
public static void shutdown()
|
||||||
|
{
|
||||||
|
FrameBufferCache fbcInstance = FrameBufferCache.getInstance();
|
||||||
|
for(Rendertarget target: fbcInstance.cache)
|
||||||
|
{
|
||||||
|
target.destroyRTT();
|
||||||
|
}
|
||||||
|
fbcInstance.cache.clear();
|
||||||
|
fbcInstance.freeMap();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There should only ever be one framebuffer cache, this function returns
|
* There should only ever be one framebuffer cache, this function returns
|
||||||
* that one framebuffer cache instance.
|
* that one framebuffer cache instance.
|
||||||
|
|
|
@ -35,9 +35,12 @@ public class Rendertarget {
|
||||||
/** The FBO ID. */
|
/** The FBO ID. */
|
||||||
private final int fboID;
|
private final int fboID;
|
||||||
|
|
||||||
/** The texture ID. */
|
/** The texture ID. for the color buffer this rendertarget renders into. */
|
||||||
private final int textureID;
|
private final int textureID;
|
||||||
|
|
||||||
|
/** The renderbuffer ID for the depth buffer that this rendertarget renders into. */
|
||||||
|
private final int depthBufferID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new FBO.
|
* Create a new FBO.
|
||||||
* @param width the width
|
* @param width the width
|
||||||
|
@ -48,6 +51,7 @@ public class Rendertarget {
|
||||||
this.height = height;
|
this.height = height;
|
||||||
fboID = GL30.glGenFramebuffers();
|
fboID = GL30.glGenFramebuffers();
|
||||||
textureID = GL11.glGenTextures();
|
textureID = GL11.glGenTextures();
|
||||||
|
depthBufferID = GL30.glGenRenderbuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,10 +103,9 @@ public class Rendertarget {
|
||||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||||
|
|
||||||
int fboDepth = GL30.glGenRenderbuffers();
|
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, buffer.depthBufferID);
|
||||||
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, fboDepth);
|
|
||||||
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, width, height);
|
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, width, height);
|
||||||
GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, fboDepth);
|
GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, buffer.depthBufferID);
|
||||||
|
|
||||||
GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, fboTexture, 0);
|
GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, fboTexture, 0);
|
||||||
GL20.glDrawBuffers(GL30.GL_COLOR_ATTACHMENT0);
|
GL20.glDrawBuffers(GL30.GL_COLOR_ATTACHMENT0);
|
||||||
|
@ -112,4 +115,15 @@ public class Rendertarget {
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the OpenGL objects associated with this Rendertarget. Do not try
|
||||||
|
* to use this rendertarget with OpenGL after calling this method.
|
||||||
|
*/
|
||||||
|
public void destroyRTT()
|
||||||
|
{
|
||||||
|
GL30.glDeleteFramebuffers(fboID);
|
||||||
|
GL30.glDeleteRenderbuffers(depthBufferID);
|
||||||
|
GL11.glDeleteTextures(textureID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user