Follow-up to #205: fixed some compile warnings.

This commit is contained in:
Jeffrey Han 2016-12-06 11:53:27 -05:00
parent 0b9a0e188d
commit 4b1dc39e4a

View File

@ -24,19 +24,17 @@ import itdelatrisu.opsu.objects.curves.Vec2f;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.EXTFramebufferObject;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.opengl.ContextCapabilities; import org.lwjgl.opengl.ContextCapabilities;
import org.lwjgl.opengl.EXTFramebufferObject;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL14; import org.lwjgl.opengl.GL14;
import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30; import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GLContext;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
@ -104,7 +102,6 @@ public class CurveRenderState {
this.curve = curve; this.curve = curve;
this.pointIndices = new int[curve.length]; this.pointIndices = new int[curve.length];
this.vboID = -1; this.vboID = -1;
} }
/** /**
@ -117,19 +114,15 @@ public class CurveRenderState {
*/ */
public void draw(Color color, Color borderColor, float t) { public void draw(Color color, Color borderColor, float t) {
t = Utils.clamp(t, 0.0f, 1.0f); t = Utils.clamp(t, 0.0f, 1.0f);
float alpha = color.a;
// create curve geometry and store it on the GPU // create curve geometry and store it on the GPU
if (vboID == -1) { if (vboID == -1) {
vboID = GL15.glGenBuffers(); vboID = GL15.glGenBuffers();
createVertexBuffer(vboID); createVertexBuffer(vboID);
} }
int drawUpTo = (int) (t * (curve.length - 1));
int drawUpTo = (int) (t * (curve.length - 1));
this.renderCurve(color, borderColor, drawUpTo); this.renderCurve(color, borderColor, drawUpTo);
//color.a = 1f;
} }
/** /**
@ -216,10 +209,7 @@ public class CurveRenderState {
*/ */
private void createVertexBuffer(int bufferID) { private void createVertexBuffer(int bufferID) {
float radius = scale / 2; float radius = scale / 2;
float mul_x = 2.f / containerWidth; int triangle_count = NewCurveStyleState.DIVIDES; // for curve caps
float mul_y = 2.f / containerHeight;
int triangle_count = staticState.DIVIDES; // for curve caps
float last_dx=0, last_dy=0; float last_dx=0, last_dy=0;
float last_alpha = 0; float last_alpha = 0;
for (int i = 0; i < curve.length; ++i) { // compute number of triangles for (int i = 0; i < curve.length; ++i) { // compute number of triangles
@ -238,10 +228,10 @@ public class CurveRenderState {
if (theta > Math.PI) theta -= 2*Math.PI; if (theta > Math.PI) theta -= 2*Math.PI;
if (theta < -Math.PI) theta += 2*Math.PI; if (theta < -Math.PI) theta += 2*Math.PI;
if (Math.abs(theta) < 2*Math.PI / staticState.DIVIDES) { if (Math.abs(theta) < 2*Math.PI / NewCurveStyleState.DIVIDES) {
triangle_count++; triangle_count++;
}else{ } else {
int divs = (int)(Math.ceil(staticState.DIVIDES * Math.abs(theta) / (2*Math.PI))); int divs = (int)(Math.ceil(NewCurveStyleState.DIVIDES * Math.abs(theta) / (2*Math.PI)));
triangle_count += divs; triangle_count += divs;
} }
} }
@ -256,24 +246,19 @@ public class CurveRenderState {
int arrayBufferBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING); int arrayBufferBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
FloatBuffer buff = BufferUtils.createByteBuffer(4 * (4 + 2) * 3 * (triangle_count)).asFloatBuffer(); FloatBuffer buff = BufferUtils.createByteBuffer(4 * (4 + 2) * 3 * (triangle_count)).asFloatBuffer();
last_dx=0; last_dy=0; last_dx=0; last_dy=0;
float last_length=0;
float last_ox=0, last_oy=0; float last_ox=0, last_oy=0;
for (int i = 0; i < curve.length; ++i) { for (int i = 0; i < curve.length; ++i) {
float x = curve[i].x; float x = curve[i].x;
float y = curve[i].y; float y = curve[i].y;
if (i > 0) { if (i > 0) {
/* /*
Render this shape: Render this shape:
___ ___ ___ ___
|A /|C /| |A /|C /|
| /B| /D| | /B| /D|
|/__|/__| |/__|/__|
*/ */
float last_x = curve[i - 1].x; float last_x = curve[i - 1].x;
float last_y = curve[i - 1].y; float last_y = curve[i - 1].y;
@ -285,15 +270,13 @@ public class CurveRenderState {
float alpha = (float)Math.atan2(diff_y, diff_x); float alpha = (float)Math.atan2(diff_y, diff_x);
if (i > 1) { if (i > 1) {
float cross = last_dx * diff_y - last_dy * diff_x; float cross = last_dx * diff_y - last_dy * diff_x;
float theta = alpha - last_alpha; float theta = alpha - last_alpha;
if (theta > Math.PI) theta -= 2*Math.PI; if (theta > Math.PI) theta -= 2*Math.PI;
if (theta < -Math.PI) theta += 2*Math.PI; if (theta < -Math.PI) theta += 2*Math.PI;
if (Math.abs(theta) < 2*Math.PI / NewCurveStyleState.DIVIDES) { // small angle, just render single triangle
if (Math.abs(theta) < 2*Math.PI / staticState.DIVIDES) { // small angle, just render single triangle
if (cross > 0) { // going counterclockwise if (cross > 0) { // going counterclockwise
buff.put(1.0f); buff.put(0.5f); buff.put(1.0f); buff.put(0.5f);
buff.put(last_x); buff.put(last_y); buff.put(last_x); buff.put(last_y);
@ -315,10 +298,10 @@ public class CurveRenderState {
buff.put(last_x - last_ox);buff.put(last_y - last_oy); buff.put(last_x - last_ox);buff.put(last_y - last_oy);
buff.put(1.0f); buff.put(1.0f); buff.put(1.0f); buff.put(1.0f);
} else { } else {
//straight line, very unlikely // straight line, very unlikely
} }
} else { } else {
int divs = (int)(Math.ceil(staticState.DIVIDES * Math.abs(theta) / (2*Math.PI))); int divs = (int)(Math.ceil(NewCurveStyleState.DIVIDES * Math.abs(theta) / (2*Math.PI)));
float phi = Math.abs(theta) / divs; float phi = Math.abs(theta) / divs;
float sinphi = (float)Math.sin(phi); float sinphi = (float)Math.sin(phi);
float cosphi = (float)Math.cos(phi); float cosphi = (float)Math.cos(phi);
@ -352,7 +335,7 @@ public class CurveRenderState {
} }
} }
} else { } else {
int divs = staticState.DIVIDES/2; int divs = NewCurveStyleState.DIVIDES / 2;
float phi = (float)(Math.PI / divs); float phi = (float)(Math.PI / divs);
float sinphi = (float)Math.sin(phi); float sinphi = (float)Math.sin(phi);
@ -419,7 +402,7 @@ public class CurveRenderState {
buff.put(1.0f); buff.put(1.0f); buff.put(1.0f); buff.put(1.0f);
if (i == curve.length-1) { if (i == curve.length-1) {
int divs = staticState.DIVIDES/2; int divs = NewCurveStyleState.DIVIDES / 2;
float phi = (float)(Math.PI / divs); float phi = (float)(Math.PI / divs);
float sinphi = (float)Math.sin(phi); float sinphi = (float)Math.sin(phi);
@ -447,21 +430,19 @@ public class CurveRenderState {
last_dx = diff_x; last_dx = diff_x;
last_dy = diff_y; last_dy = diff_y;
last_length = length;
last_ox = offs_x; last_ox = offs_x;
last_oy = offs_y; last_oy = offs_y;
last_alpha = alpha; last_alpha = alpha;
} }
pointIndices[i] = buff.position() / 6; // 6 elements per vertex pointIndices[i] = buff.position() / 6; // 6 elements per vertex
} }
buff.flip(); buff.flip();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, bufferID); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, bufferID);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, arrayBufferBinding); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, arrayBufferBinding);
} }
/** /**
* 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
@ -484,7 +465,6 @@ public class CurveRenderState {
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);
GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0); GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
GL11.glColorMask(false,false,false,false); GL11.glColorMask(false,false,false,false);
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, pointIndices[to]); GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, pointIndices[to]);
GL11.glColorMask(true,true,true,true); GL11.glColorMask(true,true,true,true);
@ -499,7 +479,6 @@ public class CurveRenderState {
restoreRenderState(state); restoreRenderState(state);
} }
/** /**
* Contains all the necessary state that needs to be tracked to draw curves * Contains all the necessary state that needs to be tracked to draw curves
* in the new style and not re-create the shader each time. * in the new style and not re-create the shader each time.