Skip to content

Commit b21ae3d

Browse files
committed
using direct allocation
1 parent 2bdc07a commit b21ae3d

File tree

4 files changed

+30
-55
lines changed

4 files changed

+30
-55
lines changed

src/main/java/com/marginallyclever/convenience/helpers/OpenGLHelper.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@
1414
*
1515
*/
1616
public class OpenGLHelper {
17-
private static final IntBuffer depthFunc = IntBuffer.allocate(1);
18-
private static final FloatBuffer lineWidth = FloatBuffer.allocate(1);
19-
2017
private static final List<Integer> errorCodes = new ArrayList<>();
21-
22-
public static int drawAtopEverythingStart(GL3 gl) {
23-
gl.glGetIntegerv(GL3.GL_DEPTH_FUNC, depthFunc);
24-
gl.glDepthFunc(GL3.GL_ALWAYS);
25-
return depthFunc.get();
26-
}
2718

2819
public static void checkGLError(GL3 gl3,org.slf4j.Logger logger) {
2920
int err = gl3.glGetError();
@@ -37,24 +28,4 @@ public static void checkGLError(GL3 gl3,org.slf4j.Logger logger) {
3728
}
3829
}
3930
}
40-
41-
public static void drawAtopEverythingEnd(GL3 gl, int previousState) {
42-
gl.glDepthFunc(previousState);
43-
}
44-
45-
public static float setLineWidth(GL3 gl,float newWidth) {
46-
gl.glGetFloatv(GL3.GL_LINE_WIDTH, lineWidth);
47-
gl.glLineWidth(newWidth);
48-
return lineWidth.get(0);
49-
}
50-
51-
public static boolean disableTextureStart(GL3 gl) {
52-
boolean b = gl.glIsEnabled(GL3.GL_TEXTURE_2D);
53-
gl.glDisable(GL3.GL_TEXTURE_2D);
54-
return b;
55-
}
56-
57-
public static void disableTextureEnd(GL3 gl,boolean oldState) {
58-
if(oldState) gl.glEnable(GL3.GL_TEXTURE_2D);
59-
}
6031
}

src/main/java/com/marginallyclever/makelangelo/Mesh.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import javax.vecmath.Vector3d;
1212
import java.beans.PropertyChangeEvent;
1313
import java.beans.PropertyChangeListener;
14+
import java.nio.ByteBuffer;
15+
import java.nio.ByteOrder;
1416
import java.nio.FloatBuffer;
1517
import java.nio.IntBuffer;
1618
import java.util.ArrayList;
@@ -142,7 +144,8 @@ private void updateBuffers(GL3 gl) {
142144
if(hasTextures) setupArray(gl,3,2,numVertexes,textureArray);
143145

144146
if(hasIndexes) {
145-
IntBuffer data = IntBuffer.allocate(indexArray.size());
147+
ByteBuffer bb = ByteBuffer.allocateDirect(indexArray.size() * Integer.BYTES).order(ByteOrder.nativeOrder());
148+
IntBuffer data = bb.asIntBuffer();
146149
for (Integer integer : indexArray) data.put(integer);
147150
data.rewind();
148151

@@ -182,7 +185,8 @@ private void bindArray(GL3 gl, int attribIndex, int size) {
182185
}
183186

184187
private void setupArray(GL3 gl, int attribIndex, int size, long numVertexes,List<Float> list) {
185-
FloatBuffer data = FloatBuffer.allocate(list.size());
188+
ByteBuffer bb = ByteBuffer.allocateDirect(list.size()*Float.BYTES).order(ByteOrder.nativeOrder());
189+
FloatBuffer data = bb.asFloatBuffer();
186190
for( Float f : list ) data.put(f);
187191
data.rewind();
188192
bindArray(gl,attribIndex,size);

src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PathImageMask.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import java.util.concurrent.locks.ReentrantLock;
1919

2020
/**
21-
* Use an image to mask a path. Lay the path over the image and remove all parts of the path where the image is brighter
22-
* than a cutoff value. The fine grain resolution (and the amount of testing) is controlled by the stepSize.
21+
* Use an [BufferedImage] to mask a [Turtle] path. Lay the path over the image and remove all parts of
22+
* the path where the image is brighter than a cutoff value. The fine grain resolution (and the amount of testing) is
23+
* controlled by the stepSize.
24+
* Another way to think of it is a union between the dark parts of the image and the path.
2325
* @author Dan Royer
2426
* @since 2022-03-08
2527
*/

src/main/java/com/marginallyclever/makelangelo/preview/ShaderProgram.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import javax.vecmath.Matrix4d;
99
import javax.vecmath.Vector3d;
1010
import java.awt.*;
11-
import java.nio.FloatBuffer;
1211
import java.security.InvalidParameterException;
1312
import java.util.HashMap;
1413
import java.util.Map;
@@ -23,7 +22,7 @@ public class ShaderProgram {
2322
private final int vertexShaderId;
2423
private final int fragmentShaderId;
2524
private final Map<String, Integer> uniformLocations = new HashMap<>();
26-
private final FloatBuffer matrixBuffer = FloatBuffer.allocate(16);
25+
private final float [] matrixBuffer = new float[16];
2726

2827
public ShaderProgram(GL3 gl, String[] vertexCode, String[] fragmentCode) {
2928
super();
@@ -141,28 +140,27 @@ public void setVector3d(GL3 gl, String name, Vector3d value) {
141140
OpenGLHelper.checkGLError(gl,logger);
142141
}
143142

144-
private FloatBuffer matrixToFloatBuffer(Matrix4d m) {
145-
matrixBuffer.put( (float)m.m00 );
146-
matrixBuffer.put( (float)m.m01 );
147-
matrixBuffer.put( (float)m.m02 );
148-
matrixBuffer.put( (float)m.m03 );
143+
private float [] matrixToFloatBuffer(Matrix4d m) {
144+
int i = 0;
145+
matrixBuffer[i++] = (float)m.m00;
146+
matrixBuffer[i++] = (float)m.m01;
147+
matrixBuffer[i++] = (float)m.m02;
148+
matrixBuffer[i++] = (float)m.m03;
149149

150-
matrixBuffer.put( (float)m.m10 );
151-
matrixBuffer.put( (float)m.m11 );
152-
matrixBuffer.put( (float)m.m12 );
153-
matrixBuffer.put( (float)m.m13 );
150+
matrixBuffer[i++] = (float)m.m10;
151+
matrixBuffer[i++] = (float)m.m11;
152+
matrixBuffer[i++] = (float)m.m12;
153+
matrixBuffer[i++] = (float)m.m13;
154154

155-
matrixBuffer.put( (float)m.m20 );
156-
matrixBuffer.put( (float)m.m21 );
157-
matrixBuffer.put( (float)m.m22 );
158-
matrixBuffer.put( (float)m.m23 );
159-
160-
matrixBuffer.put( (float)m.m30 );
161-
matrixBuffer.put( (float)m.m31 );
162-
matrixBuffer.put( (float)m.m32 );
163-
matrixBuffer.put( (float)m.m33 );
164-
matrixBuffer.rewind();
155+
matrixBuffer[i++] = (float)m.m20;
156+
matrixBuffer[i++] = (float)m.m21;
157+
matrixBuffer[i++] = (float)m.m22;
158+
matrixBuffer[i++] = (float)m.m23;
165159

160+
matrixBuffer[i++] = (float)m.m30;
161+
matrixBuffer[i++] = (float)m.m31;
162+
matrixBuffer[i++] = (float)m.m32;
163+
matrixBuffer[i++] = (float)m.m33;
166164
return matrixBuffer;
167165
}
168166

@@ -175,7 +173,7 @@ private FloatBuffer matrixToFloatBuffer(Matrix4d m) {
175173
* @param value the matrix to set
176174
*/
177175
public void setMatrix4d(GL3 gl, String name, Matrix4d value) {
178-
gl.glUniformMatrix4fv(getUniformLocation(gl, name), 1, true, matrixToFloatBuffer(value));
176+
gl.glUniformMatrix4fv(getUniformLocation(gl, name), 1, true, matrixToFloatBuffer(value),0);
179177
OpenGLHelper.checkGLError(gl,logger);
180178
}
181179

0 commit comments

Comments
 (0)