Skip to content

Commit e78d422

Browse files
committed
Initial commit
0 parents  commit e78d422

9 files changed

Lines changed: 494 additions & 0 deletions

File tree

build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group 'fr.adamaq01'
6+
version '1.0.0'
7+
8+
sourceCompatibility = 1.8
9+
10+
project.ext.lwjglVersion = "3.2.2"
11+
12+
repositories {
13+
mavenCentral()
14+
}
15+
16+
dependencies {
17+
compile "org.lwjgl:lwjgl:$lwjglVersion"
18+
compile "org.lwjgl:lwjgl-opengl:$lwjglVersion"
19+
}

gradle/wrapper/gradle-wrapper.jar

54.9 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Wed Jul 10 22:14:15 CEST 2019
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip

gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'java-osmesa'
2+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package fr.adamaq01.osmesa;
2+
3+
import org.lwjgl.system.Library;
4+
import org.lwjgl.system.MemoryUtil;
5+
import org.lwjgl.system.SharedLibrary;
6+
import org.lwjgl.system.dyncall.DynCall;
7+
8+
import java.nio.ByteBuffer;
9+
import java.nio.IntBuffer;
10+
import java.util.HashMap;
11+
12+
public class OSMesa {
13+
14+
protected static final SharedLibrary OSMESA;
15+
protected static final HashMap<Long, OSMesaContext> CONTEXTS;
16+
17+
static {
18+
OSMESA = Library.loadNative("OSMesa");
19+
CONTEXTS = new HashMap<>();
20+
}
21+
22+
public static final int OSMESA_ROW_LENGTH = 0x10;
23+
public static final int OSMESA_Y_UP = 0x11;
24+
public static final int OSMESA_WIDTH = 0x20;
25+
public static final int OSMESA_HEIGHT = 0x21;
26+
public static final int OSMESA_FORMAT = 0x22;
27+
public static final int OSMESA_TYPE = 0x23;
28+
public static final int OSMESA_MAX_WIDTH = 0x24;
29+
public static final int OSMESA_MAX_HEIGHT = 0x25;
30+
31+
public static OSMesaContext createContext(OSMesaFormat format) {
32+
long vm = DynCall.dcNewCallVM(128);
33+
DynCall.dcArgInt(vm, format.getGlId());
34+
DynCall.dcArgPointer(vm, MemoryUtil.NULL);
35+
long pointer = DynCall.dcCallPointer(vm, OSMESA.getFunctionAddress("OSMesaCreateContext"));
36+
DynCall.dcFree(vm);
37+
if (pointer == 0)
38+
throw new RuntimeException("Could not create OSMesaContext !");
39+
OSMesaContext context = new OSMesaContext(format, pointer);
40+
CONTEXTS.put(pointer, context);
41+
return context;
42+
}
43+
44+
public static OSMesaContext createContextExt(OSMesaFormat format, int depthBits, int stencilBits, int accumBits) {
45+
long vm = DynCall.dcNewCallVM(128);
46+
DynCall.dcArgInt(vm, format.getGlId());
47+
DynCall.dcArgInt(vm, depthBits);
48+
DynCall.dcArgInt(vm, stencilBits);
49+
DynCall.dcArgInt(vm, accumBits);
50+
DynCall.dcArgPointer(vm, MemoryUtil.NULL);
51+
long pointer = DynCall.dcCallPointer(vm, OSMESA.getFunctionAddress("OSMesaCreateContextExt"));
52+
DynCall.dcFree(vm);
53+
if (pointer == 0)
54+
throw new RuntimeException("Could not create OSMesaContext !");
55+
OSMesaContext context = new OSMesaContext(format, pointer);
56+
CONTEXTS.put(pointer, context);
57+
return context;
58+
}
59+
60+
public static void destroyContext(OSMesaContext context) {
61+
context.destroy();
62+
}
63+
64+
public static ByteBuffer makeContextCurrent(OSMesaContext context, int width, int height) {
65+
return context.makeCurrent(width, height);
66+
}
67+
68+
public static OSMesaContext getCurrentContext() {
69+
long vm = DynCall.dcNewCallVM(64);
70+
long pointer = DynCall.dcCallPointer(vm, OSMESA.getFunctionAddress("OSMesaGetCurrentContext"));
71+
DynCall.dcFree(vm);
72+
if (pointer == 0)
73+
throw new RuntimeException("Could not get current OSMesaContext !");
74+
OSMesaContext context = CONTEXTS.get(pointer);
75+
if (context == null) {
76+
context = new OSMesaContext(OSMesaFormat.fromGlId(getIntegerv(OSMESA_FORMAT)), pointer);
77+
CONTEXTS.put(pointer, context);
78+
}
79+
return context;
80+
}
81+
82+
public static int getIntegerv(int property) {
83+
IntBuffer value = MemoryUtil.memAllocInt(1);
84+
long vm = DynCall.dcNewCallVM(128);
85+
DynCall.dcArgInt(vm, property);
86+
DynCall.dcArgPointer(vm, MemoryUtil.memAddress(value));
87+
DynCall.dcCallVoid(vm, OSMesa.OSMESA.getFunctionAddress("OSMesaGetIntegerv"));
88+
DynCall.dcFree(vm);
89+
return value.get(0);
90+
}
91+
}

0 commit comments

Comments
 (0)