diff --git a/examples-lwjgl/pom.xml b/examples-lwjgl/pom.xml index fcf1e25..7b8ae81 100644 --- a/examples-lwjgl/pom.xml +++ b/examples-lwjgl/pom.xml @@ -118,4 +118,4 @@ - \ No newline at end of file + diff --git a/lib/src/main/java/net/opengrabeso/glg2d/VertexBuffer.java b/lib/src/main/java/net/opengrabeso/glg2d/VertexBuffer.java index 7dbfb9c..456e021 100644 --- a/lib/src/main/java/net/opengrabeso/glg2d/VertexBuffer.java +++ b/lib/src/main/java/net/opengrabeso/glg2d/VertexBuffer.java @@ -17,10 +17,9 @@ import java.nio.FloatBuffer; -import com.github.opengrabeso.jaagl.GL; import com.github.opengrabeso.jaagl.GL2; -import com.jogamp.common.nio.Buffers; +import net.opengrabeso.opengl.util.buffers.Buffers; /** * Wraps a simple {@code FloatBuffer} and makes it easier to push 2-D vertices diff --git a/lib/src/main/java/net/opengrabeso/glg2d/impl/BasicStrokeLineVisitor.java b/lib/src/main/java/net/opengrabeso/glg2d/impl/BasicStrokeLineVisitor.java index 28618b7..4ec46c3 100644 --- a/lib/src/main/java/net/opengrabeso/glg2d/impl/BasicStrokeLineVisitor.java +++ b/lib/src/main/java/net/opengrabeso/glg2d/impl/BasicStrokeLineVisitor.java @@ -27,7 +27,7 @@ import net.opengrabeso.glg2d.VertexBuffer; -import com.jogamp.common.nio.Buffers; +import net.opengrabeso.opengl.util.buffers.Buffers; /** * Draws a line, as outlined by a {@link BasicStroke}. The current @@ -584,4 +584,4 @@ protected void addVertex(float x, float y) { } protected abstract void drawBuffer(); -} \ No newline at end of file +} diff --git a/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/AnyModePipeline.java b/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/AnyModePipeline.java index 9a9f955..cf44ad7 100644 --- a/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/AnyModePipeline.java +++ b/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/AnyModePipeline.java @@ -19,8 +19,6 @@ import com.github.opengrabeso.jaagl.GL2GL3; -import com.jogamp.common.nio.Buffers; - public class AnyModePipeline extends AbstractShaderPipeline { protected int vertCoordBuffer = -1; protected int vertCoordLocation = -1; @@ -58,7 +56,7 @@ public void bindBufferData(GL2GL3 gl, FloatBuffer vertexBuffer) { bindBuffer(gl); int count = vertexBuffer.limit() - vertexBuffer.position(); - gl.glBufferData(gl.GL_ARRAY_BUFFER(), Buffers.SIZEOF_FLOAT * count, vertexBuffer, gl.GL_STREAM_DRAW()); + gl.glBufferData(gl.GL_ARRAY_BUFFER(), Float.BYTES * count, vertexBuffer, gl.GL_STREAM_DRAW()); } public void unbindBuffer(GL2GL3 gl) { diff --git a/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GL2ES2ImageDrawer.java b/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GL2ES2ImageDrawer.java index f4913c4..ee2b610 100644 --- a/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GL2ES2ImageDrawer.java +++ b/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GL2ES2ImageDrawer.java @@ -20,15 +20,13 @@ import java.awt.geom.AffineTransform; import java.nio.FloatBuffer; -import com.github.opengrabeso.jaagl.GL; import com.github.opengrabeso.jaagl.GL2GL3; -import com.github.opengrabeso.jaagl.jogl.JoGL; +import net.opengrabeso.opengl.util.buffers.Buffers; import net.opengrabeso.opengl.util.texture.Texture; import net.opengrabeso.glg2d.GLGraphics2D; import net.opengrabeso.glg2d.impl.AbstractImageHelper; -import com.jogamp.common.nio.Buffers; public class GL2ES2ImageDrawer extends AbstractImageHelper { protected GLShaderGraphics2D g2d; diff --git a/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GL2ES2ImagePipeline.java b/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GL2ES2ImagePipeline.java index d852948..5c29847 100644 --- a/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GL2ES2ImagePipeline.java +++ b/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GL2ES2ImagePipeline.java @@ -21,8 +21,6 @@ import com.github.opengrabeso.jaagl.GL2GL3; -import com.jogamp.common.nio.Buffers; - public class GL2ES2ImagePipeline extends AbstractShaderPipeline { protected int vertexBufferId = -1; protected int vertexArrayId = -1; @@ -61,10 +59,10 @@ protected void bufferData(GL2GL3 gl, FloatBuffer buffer) { gl.glEnableVertexAttribArray(texCoordLocation); gl.glBindBuffer(gl.GL_ARRAY_BUFFER(), vertexBufferId); - gl.glBufferData(gl.GL_ARRAY_BUFFER(), Buffers.SIZEOF_FLOAT * 16, buffer, gl.GL_STATIC_DRAW()); + gl.glBufferData(gl.GL_ARRAY_BUFFER(), Float.BYTES * 16, buffer, gl.GL_STATIC_DRAW()); - gl.glVertexAttribPointer(vertCoordLocation, 2, gl.GL_FLOAT(), false, 4 * Buffers.SIZEOF_FLOAT, 0); - gl.glVertexAttribPointer(texCoordLocation, 2, gl.GL_FLOAT(), false, 4 * Buffers.SIZEOF_FLOAT, 2 * Buffers.SIZEOF_FLOAT); + gl.glVertexAttribPointer(vertCoordLocation, 2, gl.GL_FLOAT(), false, 4 * Float.BYTES, 0); + gl.glVertexAttribPointer(texCoordLocation, 2, gl.GL_FLOAT(), false, 4 * Float.BYTES, 2 * Float.BYTES); } public void draw(GL2GL3 gl, FloatBuffer interleavedVertTexBuffer) { diff --git a/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GeometryShaderStrokePipeline.java b/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GeometryShaderStrokePipeline.java index 86703e1..0b42092 100644 --- a/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GeometryShaderStrokePipeline.java +++ b/lib/src/main/java/net/opengrabeso/glg2d/impl/shader/GeometryShaderStrokePipeline.java @@ -23,7 +23,7 @@ import net.opengrabeso.glg2d.GLG2DUtils; -import com.jogamp.common.nio.Buffers; +import net.opengrabeso.opengl.util.buffers.Buffers; public class GeometryShaderStrokePipeline extends AbstractShaderPipeline { public static final int DRAW_END_NONE = 0; @@ -85,17 +85,17 @@ protected void bindBuffer(GL2GL3 gl, FloatBuffer vertexBuffer) { if (gl.glIsBuffer(vertCoordBuffer)) { gl.glBindBuffer(gl.GL_ARRAY_BUFFER(), vertCoordBuffer); - gl.glBufferSubData(gl.GL_ARRAY_BUFFER(), 0, Buffers.SIZEOF_FLOAT * vertexBuffer.limit(), vertexBuffer); + gl.glBufferSubData(gl.GL_ARRAY_BUFFER(), 0, Float.BYTES * vertexBuffer.limit(), vertexBuffer); } else { vertCoordBuffer = GLG2DUtils.genBufferId(gl); gl.glBindBuffer(gl.GL_ARRAY_BUFFER(), vertCoordBuffer); - gl.glBufferData(gl.GL_ARRAY_BUFFER(), Buffers.SIZEOF_FLOAT * vertexBuffer.capacity(), vertexBuffer, gl.GL_STREAM_DRAW()); + gl.glBufferData(gl.GL_ARRAY_BUFFER(), Float.BYTES * vertexBuffer.capacity(), vertexBuffer, gl.GL_STREAM_DRAW()); } - gl.glVertexAttribPointer(vertCoordLocation, 2, gl.GL_FLOAT(), false, 0, 2 * Buffers.SIZEOF_FLOAT); + gl.glVertexAttribPointer(vertCoordLocation, 2, gl.GL_FLOAT(), false, 0, 2 * Float.BYTES); gl.glVertexAttribPointer(vertBeforeLocation, 2, gl.GL_FLOAT(), false, 0, 0); - gl.glVertexAttribPointer(vertAfterLocation, 2, gl.GL_FLOAT(), false, 0, 4 * Buffers.SIZEOF_FLOAT); + gl.glVertexAttribPointer(vertAfterLocation, 2, gl.GL_FLOAT(), false, 0, 4 * Float.BYTES); } public void draw(GL2GL3 gl, FloatBuffer vertexBuffer, boolean close) { diff --git a/lib/src/main/java/net/opengrabeso/opengl/util/awt/Pipelined_QuadRenderer.java b/lib/src/main/java/net/opengrabeso/opengl/util/awt/Pipelined_QuadRenderer.java index 1dcfc59..7ec226c 100644 --- a/lib/src/main/java/net/opengrabeso/opengl/util/awt/Pipelined_QuadRenderer.java +++ b/lib/src/main/java/net/opengrabeso/opengl/util/awt/Pipelined_QuadRenderer.java @@ -1,7 +1,7 @@ package net.opengrabeso.opengl.util.awt; import com.github.opengrabeso.jaagl.GL2GL3; -import com.jogamp.common.nio.Buffers; +import net.opengrabeso.opengl.util.buffers.Buffers; import net.opengrabeso.opengl.util.texture.TextureCoords; import java.nio.FloatBuffer; diff --git a/lib/src/main/java/net/opengrabeso/opengl/util/awt/TextureRenderer.java b/lib/src/main/java/net/opengrabeso/opengl/util/awt/TextureRenderer.java index 3a930bc..17009fc 100644 --- a/lib/src/main/java/net/opengrabeso/opengl/util/awt/TextureRenderer.java +++ b/lib/src/main/java/net/opengrabeso/opengl/util/awt/TextureRenderer.java @@ -52,8 +52,6 @@ import java.io.InputStreamReader; import com.github.opengrabeso.jaagl.GL2GL3; -import com.jogamp.common.nio.Buffers; -import net.opengrabeso.glg2d.impl.shader.AbstractShaderPipeline; import net.opengrabeso.glg2d.impl.shader.AnyModePipeline; import net.opengrabeso.opengl.util.texture.*; import net.opengrabeso.opengl.util.texture.awt.*; @@ -197,8 +195,8 @@ private void setupVertexAttributesImpl() { gl.glEnableVertexAttribArray(vertCoordAttrib); gl.glEnableVertexAttribArray(texCoordAttrib); - gl.glVertexAttribPointer(vertCoordAttrib, 3, gl.GL_FLOAT(), false, 5 * Buffers.SIZEOF_FLOAT, 0); - gl.glVertexAttribPointer(texCoordAttrib, 2, gl.GL_FLOAT(), false, 5 * Buffers.SIZEOF_FLOAT, 3 * Buffers.SIZEOF_FLOAT); + gl.glVertexAttribPointer(vertCoordAttrib, 3, gl.GL_FLOAT(), false, 5 * Float.BYTES, 0); + gl.glVertexAttribPointer(texCoordAttrib, 2, gl.GL_FLOAT(), false, 5 * Float.BYTES, 3 * Float.BYTES); } private void cleanupVertexAttributesImpl() { diff --git a/lib/src/main/java/net/opengrabeso/opengl/util/buffers/Buffers.java b/lib/src/main/java/net/opengrabeso/opengl/util/buffers/Buffers.java new file mode 100644 index 0000000..c78b28b --- /dev/null +++ b/lib/src/main/java/net/opengrabeso/opengl/util/buffers/Buffers.java @@ -0,0 +1,13 @@ +package net.opengrabeso.opengl.util.buffers; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +public class Buffers { + static public FloatBuffer newDirectFloatBuffer(int size) { + return ByteBuffer.allocateDirect(size * Float.BYTES) + .order(ByteOrder.nativeOrder()) + .asFloatBuffer(); + } +}