Follow-up to #91.

Pass the border color into CurveRenderState instead of determining it there; store the color as a static field in Curve (since it shouldn't change per-beatmap).

Also removed the leftover FrameBufferCache warning from #64.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-06-08 16:42:54 -04:00
parent a7d05a4b26
commit b1b1664e11
4 changed files with 16 additions and 21 deletions

View File

@ -39,6 +39,9 @@ public abstract class Curve {
/** Points generated along the curve should be spaced this far apart. */ /** Points generated along the curve should be spaced this far apart. */
protected static float CURVE_POINTS_SEPERATION = 5; protected static float CURVE_POINTS_SEPERATION = 5;
/** The curve border color. */
private static Color borderColor;
/** Whether OpenGL 3.0 is supported. */ /** Whether OpenGL 3.0 is supported. */
private static boolean openGL30 = false; private static boolean openGL30 = false;
@ -77,8 +80,10 @@ public abstract class Curve {
* @param width the container width * @param width the container width
* @param height the container height * @param height the container height
* @param circleSize the circle size * @param circleSize the circle size
* @param borderColor the curve border color
*/ */
public static void init(int width, int height, float circleSize) { public static void init(int width, int height, float circleSize, Color borderColor) {
Curve.borderColor = borderColor;
openGL30 = GLContext.getCapabilities().OpenGL30; openGL30 = GLContext.getCapabilities().OpenGL30;
if (openGL30) if (openGL30)
CurveRenderState.init(width, height, circleSize); CurveRenderState.init(width, height, circleSize);
@ -117,7 +122,7 @@ public abstract class Curve {
else { else {
if (renderState == null) if (renderState == null)
renderState = new CurveRenderState(hitObject); renderState = new CurveRenderState(hitObject);
renderState.draw(color, curve); renderState.draw(color, borderColor, curve);
} }
} }

View File

@ -18,9 +18,7 @@
package itdelatrisu.opsu.render; package itdelatrisu.opsu.render;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.beatmap.HitObject; import itdelatrisu.opsu.beatmap.HitObject;
import itdelatrisu.opsu.objects.curves.Vec2f; import itdelatrisu.opsu.objects.curves.Vec2f;
@ -92,9 +90,10 @@ public class CurveRenderState {
* this is called this caches the image result of the curve and on subsequent * this is called this caches the image result of the curve and on subsequent
* runs it just draws the cached copy to the screen. * runs it just draws the cached copy to the screen.
* @param color tint of the curve * @param color tint of the curve
* @param borderColor the curve border color
* @param curve the points along the curve to be drawn * @param curve the points along the curve to be drawn
*/ */
public void draw(Color color, Vec2f[] curve) { public void draw(Color color, Color borderColor, Vec2f[] curve) {
float alpha = color.a; float alpha = color.a;
// if this curve hasn't been drawn, draw it and cache the result // if this curve hasn't been drawn, draw it and cache the result
@ -113,7 +112,7 @@ public class CurveRenderState {
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
Utils.COLOR_WHITE_FADE.a = 1.0f; Utils.COLOR_WHITE_FADE.a = 1.0f;
this.draw_curve(color, curve); this.draw_curve(color, borderColor, curve);
color.a = 1f; color.a = 1f;
GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_tex); GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_tex);
@ -229,9 +228,10 @@ public class CurveRenderState {
/** /**
* Do the actual drawing of the curve into the currently bound framebuffer. * Do the actual drawing of the curve into the currently bound framebuffer.
* @param color the color of the curve * @param color the color of the curve
* @param borderColor the curve border color
* @param curve the points along the curve * @param curve the points along the curve
*/ */
private void draw_curve(Color color, Vec2f[] curve) { private void draw_curve(Color color, Color borderColor, Vec2f[] curve) {
staticState.initGradient(); staticState.initGradient();
RenderState state = startRender(); RenderState state = startRender();
int vtx_buf; int vtx_buf;
@ -262,12 +262,7 @@ public class CurveRenderState {
GL20.glEnableVertexAttribArray(staticState.texCoordLoc); GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
GL20.glUniform1i(staticState.texLoc, 0); GL20.glUniform1i(staticState.texLoc, 0);
GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b); GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
Color borderColor; GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
if(Options.isBeatmapSkinIgnored())
borderColor = Options.getSkin().getSliderBorderColor();
else
borderColor = MusicController.getBeatmap().getSliderBorderColor();
GL20.glUniform4f(staticState.colBorderLoc,borderColor.r,borderColor.g,borderColor.b,borderColor.a);
//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w) //stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
//2*4 is for skipping the first 2 floats (u,v) //2*4 is for skipping the first 2 floats (u,v)
GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4); GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
@ -356,7 +351,7 @@ public class CurveRenderState {
/** OpenGL shader uniform location of the color attribute. */ /** OpenGL shader uniform location of the color attribute. */
protected int colLoc = 0; protected int colLoc = 0;
/** OpenGL shader uniform location of the border color attribute */ /** OpenGL shader uniform location of the border color attribute. */
protected int colBorderLoc = 0; protected int colBorderLoc = 0;
/** OpenGL shader uniform location of the texture sampler attribute. */ /** OpenGL shader uniform location of the texture sampler attribute. */

View File

@ -23,8 +23,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.newdawn.slick.util.Log;
/** /**
* This is cache for OpenGL FrameBufferObjects. This is currently only used * This is cache for OpenGL FrameBufferObjects. This is currently only used
* to draw curve objects of the new slider style. Does currently not integrate * to draw curve objects of the new slider style. Does currently not integrate
@ -33,9 +31,6 @@ import org.newdawn.slick.util.Log;
* @author Bigpet {@literal <dravorek (at) gmail.com>} * @author Bigpet {@literal <dravorek (at) gmail.com>}
*/ */
public class FrameBufferCache { public class FrameBufferCache {
/** The initial cache size. */
//private static final int INITIAL_CACHE_SIZE = 4;
/** The single framebuffer cache instance. */ /** The single framebuffer cache instance. */
private static FrameBufferCache instance = null; private static FrameBufferCache instance = null;
@ -123,7 +118,6 @@ public class FrameBufferCache {
// no unmapped RTTFramebuffer found, create a new one // no unmapped RTTFramebuffer found, create a new one
buffer = Rendertarget.createRTTFramebuffer(width, height); buffer = Rendertarget.createRTTFramebuffer(width, height);
cache.add(buffer); cache.add(buffer);
Log.warn("Framebuffer cache was not large enough, possible resource leak.");
cacheMap.put(obj, buffer); cacheMap.put(obj, buffer);
return buffer; return buffer;
} }

View File

@ -1393,7 +1393,8 @@ public class Game extends BasicGameState {
Circle.init(container, circleSize); Circle.init(container, circleSize);
Slider.init(container, circleSize, beatmap); Slider.init(container, circleSize, beatmap);
Spinner.init(container); Spinner.init(container);
Curve.init(container.getWidth(), container.getHeight(), circleSize); Curve.init(container.getWidth(), container.getHeight(), circleSize, (Options.isBeatmapSkinIgnored()) ?
Options.getSkin().getSliderBorderColor() : beatmap.getSliderBorderColor());
// approachRate (hit object approach time) // approachRate (hit object approach time)
if (approachRate < 5) if (approachRate < 5)