Skip to content

Commit

Permalink
Initial com.mexa.opgl implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
woesss committed Jan 3, 2024
1 parent a22354e commit e904fa1
Show file tree
Hide file tree
Showing 8 changed files with 564 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

- name: Calculate version suffix
run:
echo "VERSION_SUFFIX=-${GITHUB_SHA::7}" >> $GITHUB_ENV
echo "VERSION_SUFFIX=$(git show -s --abbrev=7 --format=-%cd-%h --date=format:%y%m%d)" >> $GITHUB_ENV

- name: Build with Gradle
run: ./gradlew assembleEmulatorRelease
Expand Down
25 changes: 23 additions & 2 deletions app/src/main/java/com/mexa/opgl/Buffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,38 @@

package com.mexa.opgl;

import android.os.Build;

public abstract class Buffer {
Buffer() {
final java.nio.Buffer buffer;
int offset;
int length;

Buffer(java.nio.Buffer buffer) {
this.buffer = buffer;
length = buffer.capacity();
}

public int length() {
return 0;
return length;
}

public synchronized void setBounds(int offset, int length) {
this.offset = offset;
this.length = length;
}

public synchronized void resetBounds() {
offset = 0;
length = buffer.capacity();
}

final java.nio.Buffer getNioBuffer() {
buffer.rewind();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
return buffer.slice(offset, length);
} else {
return buffer.position(offset).limit(length);
}
}
}
22 changes: 19 additions & 3 deletions app/src/main/java/com/mexa/opgl/ByteBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,38 @@

package com.mexa.opgl;

import ru.woesss.j2me.micro3d.BufferUtils;

public class ByteBuffer extends Buffer {
private ByteBuffer() {

private ByteBuffer(int size) {
super(BufferUtils.createByteBuffer(size));
}

private ByteBuffer(ByteBuffer buffer) {
this(buffer.length());
java.nio.ByteBuffer nio = (java.nio.ByteBuffer) super.buffer;
nio.put((java.nio.ByteBuffer) buffer.getNioBuffer());
}

public static ByteBuffer allocateDirect(int size) {
return new ByteBuffer();
return new ByteBuffer(size);
}

public static ByteBuffer allocateDirect(ByteBuffer buffer) {
return buffer;
return new ByteBuffer(buffer);
}

public byte[] get(int srcIndex, byte[] buf, int dstIndex, int length) {
java.nio.ByteBuffer nio = (java.nio.ByteBuffer) super.buffer;
nio.position(srcIndex);
nio.get(buf, dstIndex, length);
return buf;
}

public void put(int dstIndex, byte[] buf, int srcIndex, int length) {
java.nio.ByteBuffer nio = (java.nio.ByteBuffer) super.buffer;
nio.position(dstIndex);
nio.put(buf, srcIndex, length);
}
}
22 changes: 19 additions & 3 deletions app/src/main/java/com/mexa/opgl/FloatBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,38 @@

package com.mexa.opgl;

import ru.woesss.j2me.micro3d.BufferUtils;

public class FloatBuffer extends Buffer {
private FloatBuffer() {

private FloatBuffer(int size) {
super(BufferUtils.createFloatBuffer(size));
}

private FloatBuffer(FloatBuffer buffer) {
this(buffer.length());
java.nio.FloatBuffer nio = (java.nio.FloatBuffer) super.buffer;
nio.put((java.nio.FloatBuffer) buffer.getNioBuffer());
}

public static FloatBuffer allocateDirect(int size) {
return new FloatBuffer();
return new FloatBuffer(size);
}

public static FloatBuffer allocateDirect(FloatBuffer buffer) {
return buffer;
return new FloatBuffer(buffer);
}

public float[] get(int srcIndex, float[] buf, int dstIndex, int length) {
java.nio.FloatBuffer nio = (java.nio.FloatBuffer) super.buffer;
nio.position(srcIndex);
nio.get(buf, dstIndex, length);
return buf;
}

public void put(int dstIndex, float[] buf, int srcIndex, int length) {
java.nio.FloatBuffer nio = (java.nio.FloatBuffer) super.buffer;
nio.position(dstIndex);
nio.put(buf, srcIndex, length);
}
}
22 changes: 19 additions & 3 deletions app/src/main/java/com/mexa/opgl/IntBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,38 @@

package com.mexa.opgl;

import ru.woesss.j2me.micro3d.BufferUtils;

public class IntBuffer extends Buffer {
private IntBuffer() {

private IntBuffer(int size) {
super(BufferUtils.createIntBuffer(size));
}

private IntBuffer(IntBuffer buffer) {
this(buffer.length());
java.nio.IntBuffer nio = (java.nio.IntBuffer) super.buffer;
nio.put((java.nio.IntBuffer) buffer.getNioBuffer());
}

public static IntBuffer allocateDirect(int size) {
return new IntBuffer();
return new IntBuffer(size);
}

public static IntBuffer allocateDirect(IntBuffer buffer) {
return buffer;
return new IntBuffer(buffer);
}

public int[] get(int srcIndex, int[] buf, int dstIndex, int length) {
java.nio.IntBuffer nio = (java.nio.IntBuffer) super.buffer;
nio.position(srcIndex);
nio.get(buf, dstIndex, length);
return buf;
}

public void put(int dstIndex, int[] buf, int srcIndex, int length) {
java.nio.IntBuffer nio = (java.nio.IntBuffer) super.buffer;
nio.position(dstIndex);
nio.put(buf, srcIndex, length);
}
}
Loading

0 comments on commit e904fa1

Please sign in to comment.