X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=UIImplementation.pde;h=e0b57876ac4fd182fefa6df6b9ec874de6c039bd;hb=30624e974f88224b0a8719b11bd649578eb97ab6;hp=7750ab930c365a3322d635b6f82728483f0bca7c;hpb=7d60f6f6ea82fd5c9794524ce11d40e7d6c00bf7;p=SugarCubes.git diff --git a/UIImplementation.pde b/UIImplementation.pde index 7750ab9..e0b5787 100644 --- a/UIImplementation.pde +++ b/UIImplementation.pde @@ -10,9 +10,69 @@ * * Custom UI components using the framework. */ + +import java.nio.*; import java.util.Arrays; class UICubesLayer extends UICameraComponent { + +int nvert = 200000; +int SIZEOF_INT = Integer.SIZE / 8; +int SIZEOF_FLOAT = Float.SIZE / 8; + +PGL pgl; +PShader sh; + +int vertLoc; +int colorLoc; + +IntBuffer vboName; +FloatBuffer vertData; + + boolean initted = false; + PShape sha1; + int numPoints = 10000; + + void initme() + { + nvert = model.points.size(); + sh = loadShader("frag.glsl", "vert.glsl"); + /*color[] simulationColors = lx.getColors(); + sha1= createShape(); + sha1.beginShape(POINTS); + for (LXPoint p : model.points) { + stroke(simulationColors[p.index]); + //pointColor(simulationColors[p.index]); + gl2.glPointColor=100; + sha1.vertex(p.x, p.y, p.z); + } + sha1.endShape();*/ + float[] temp = new float[nvert * 7]; + for (LXPoint p : model.points) { + // position + temp[p.index * 7 + 0] = p.x; + temp[p.index * 7 + 1] = p.y; + temp[p.index * 7 + 2] = p.z; + + // color + temp[p.index * 7 + 3] = 0.0; + temp[p.index * 7 + 4] = 0.0; + temp[p.index * 7 + 5] = 0.0; + temp[p.index * 7 + 6] = 1.0; + } + + vertData = allocateDirectFloatBuffer(nvert * 7); + vertData.rewind(); + vertData.put(temp); + vertData.position(0); + vboName = allocateDirectIntBuffer(1); + initVBO(); + } void onDraw(UI ui) { + if(!initted) + { + initted=true; + initme(); + } color[] simulationColors = lx.getColors(); String displayMode = uiCrossfader.getDisplayMode(); if (displayMode == "A") { @@ -23,19 +83,18 @@ class UICubesLayer extends UICameraComponent { long simulationStart = System.nanoTime(); if (simulationOn) { + hint(DISABLE_DEPTH_TEST); drawSimulation(simulationColors); + hint(ENABLE_DEPTH_TEST); } simulationNanos = System.nanoTime() - simulationStart; - - camera(); - PGraphicsOpenGL gl = (PGraphicsOpenGL) g; + camera(); strokeWeight(1); } void drawSimulation(color[] simulationColors) { translate(0, 30, 0); - - noStroke(); + fill(#141414); drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.); fill(#070707); @@ -59,22 +118,72 @@ class UICubesLayer extends UICameraComponent { for (Cube c : model.cubes) { drawCube(c); } - + noFill(); - strokeWeight(2); - beginShape(POINTS); + //strokeWeight(2); + int count=0; + + ///magic: + + pgl = beginPGL(); + + + sh.bind(); + + vertLoc = pgl.getAttribLocation(sh.glProgram, "vertex"); + colorLoc = pgl.getAttribLocation(sh.glProgram, "color"); + + pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0)); + pgl.enableVertexAttribArray(vertLoc); + pgl.enableVertexAttribArray(colorLoc); + + pgl.vertexAttribPointer(vertLoc, 3, PGL.FLOAT, false, 7 * SIZEOF_FLOAT, 0); + pgl.vertexAttribPointer(colorLoc, 4, PGL.FLOAT, false, 7 * SIZEOF_FLOAT, 3 * SIZEOF_FLOAT); + javax.media.opengl.GL2 gl2 = (javax.media.opengl.GL2) ((PJOGL)pgl).gl; + gl2.glPointSize(2f); + pgl.drawArrays(PGL.POINTS, 0, nvert); + + pgl.disableVertexAttribArray(vertLoc); + pgl.disableVertexAttribArray(colorLoc); + pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); + + sh.unbind(); + endPGL(); + createGeometry(simulationColors); + pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0)); + pgl.bufferData(PGL.ARRAY_BUFFER, nvert * 7 * SIZEOF_FLOAT, vertData, PGL.STATIC_DRAW); + } + + void createGeometry(color[] simulationColors) { for (LXPoint p : model.points) { - stroke(simulationColors[p.index]); - vertex(p.x, p.y, p.z); - } - endShape(); + vertData.put(p.index * 7 + 3, ((simulationColors[p.index] >> 16) & 0xFF)/255.0); + vertData.put(p.index * 7 + 4, ((simulationColors[p.index] >> 8) & 0xFF)/255.0); + vertData.put(p.index * 7 + 5, (simulationColors[p.index]& 0xFF)/255.0); + } } +void initVBO() { + + pgl = beginPGL(); + pgl.genBuffers(1, vboName); + pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0)); + pgl.bufferData(PGL.ARRAY_BUFFER, nvert * 7 * SIZEOF_FLOAT, vertData, PGL.DYNAMIC_DRAW); + pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); + endPGL(); +} + +IntBuffer allocateDirectIntBuffer(int n) { + return ByteBuffer.allocateDirect(n * SIZEOF_INT).order(ByteOrder.nativeOrder()).asIntBuffer(); +} + +FloatBuffer allocateDirectFloatBuffer(int n) { + return ByteBuffer.allocateDirect(n * SIZEOF_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); +} void drawCube(Cube c) { float in = .15; noStroke(); fill(#393939); - drawBox(c.x+in, c.y+in, c.z+in, c.rx, c.ry, c.rz, Cube.EDGE_WIDTH-in*2, Cube.EDGE_HEIGHT-in*2, Cube.EDGE_WIDTH-in*2, Cube.CHANNEL_WIDTH-in); + // drawBox(c.x+in, c.y+in, c.z+in, c.rx, c.ry, c.rz, Cube.EDGE_WIDTH-in*2, Cube.EDGE_HEIGHT-in*2, Cube.EDGE_WIDTH-in*2, Cube.CHANNEL_WIDTH-in); } void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) { @@ -113,12 +222,12 @@ class UICubesLayer extends UICameraComponent { class UIBlendMode extends UIWindow { public UIBlendMode(float x, float y, float w, float h) { super(lx.ui, "BLEND MODE", x, y, w, h); - List items = new ArrayList(); + List items = new ArrayList(); for (LXTransition t : transitions) { - items.add(new TransitionScrollItem(t)); + items.add(new TransitionItem(t)); } - final UIScrollList tList; - (tList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 60)).setItems(items).addToContainer(this); + final UIItemList tList; + (tList = new UIItemList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 60)).setItems(items).addToContainer(this); lx.engine.getDeck(RIGHT_DECK).addListener(new LXDeck.AbstractListener() { public void faderTransitionDidChange(LXDeck deck, LXTransition transition) { @@ -127,11 +236,11 @@ class UIBlendMode extends UIWindow { }); } - class TransitionScrollItem extends UIScrollList.AbstractItem { + class TransitionItem extends UIItemList.AbstractItem { private final LXTransition transition; private final String label; - TransitionScrollItem(LXTransition transition) { + TransitionItem(LXTransition transition) { this.transition = transition; this.label = className(transition, "Transition"); } @@ -181,12 +290,12 @@ class UIEffects extends UIWindow { super(lx.ui, "FX", x, y, w, h); int yp = UIWindow.TITLE_LABEL_HEIGHT; - List items = new ArrayList(); + List items = new ArrayList(); int i = 0; for (LXEffect fx : effectsArr) { items.add(new FXScrollItem(fx, i++)); } - final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items); + final UIItemList effectsList = new UIItemList(1, yp, w-2, 60).setItems(items); effectsList.addToContainer(this); yp += effectsList.getHeight() + 10; @@ -218,7 +327,7 @@ class UIEffects extends UIWindow { } - class FXScrollItem extends UIScrollList.AbstractItem { + class FXScrollItem extends UIItemList.AbstractItem { private final LXEffect effect; private final int index; @@ -269,9 +378,9 @@ class UIOutput extends UIWindow { super(lx.ui, "OUTPUT", x, y, w, h); float yp = UIWindow.TITLE_LABEL_HEIGHT; - final UIScrollList outputs = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 80); + final UIItemList outputs = new UIItemList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 80); - List items = new ArrayList(); + List items = new ArrayList(); for (GrizzlyOutput grizzly : grizzlies) { items.add(new GrizzlyScrollItem(grizzly)); grizzly.enabled.addListener(new LXParameterListener() { @@ -283,7 +392,7 @@ class UIOutput extends UIWindow { outputs.setItems(items).addToContainer(this); } - class GrizzlyScrollItem extends UIScrollList.AbstractItem { + class GrizzlyScrollItem extends UIItemList.AbstractItem { final GrizzlyOutput output; GrizzlyScrollItem(GrizzlyOutput output) { @@ -389,7 +498,7 @@ class UIMapping extends UIWindow { yp += 10; - new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new UIScrollList.Item[] { + new UIItemList(1, yp, w-2, 60).setItems(Arrays.asList(new UIItemList.Item[] { new ColorScrollItem(ColorScrollItem.COLOR_RED), new ColorScrollItem(ColorScrollItem.COLOR_GREEN), new ColorScrollItem(ColorScrollItem.COLOR_BLUE), @@ -431,7 +540,7 @@ class UIMapping extends UIWindow { stripBox.setValue(value); } - class ColorScrollItem extends UIScrollList.AbstractItem { + class ColorScrollItem extends UIItemList.AbstractItem { public static final int COLOR_RED = 1; public static final int COLOR_GREEN = 2; @@ -535,12 +644,12 @@ class UIMidi extends UIWindow { super(lx.ui, "MIDI", x, y, w, h); // Processing compiler doesn't seem to get that list of class objects also conform to interface - List scrollItems = new ArrayList(); + List scrollItems = new ArrayList(); for (SCMidiInput mc : midiEngine.getControllers()) { scrollItems.add(mc); } - final UIScrollList scrollList; - (scrollList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 100)).setItems(scrollItems).addToContainer(this); + final UIItemList scrollList; + (scrollList = new UIItemList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 100)).setItems(scrollItems).addToContainer(this); (deckMode = new UIToggleSet(4, 130, 90, 20) { protected void onToggle(String value) { midiEngine.setFocusedDeck(value == "A" ? 0 : 1);