forked from eclipse-efx/efxclipse-drift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jni_GL.cpp
263 lines (211 loc) · 10.2 KB
/
jni_GL.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
* Copyright (c) 2020 BestSolution.at and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christoph Caks <ccaks@bestsolution.at> - initial API and implementation
*/
#include <jni.h>
#include <DriftGL.h>
#include <iostream>
using namespace driftgl;
extern "C" JNIEXPORT jboolean JNICALL Java_org_eclipse_fx_drift_internal_GL_initialize(JNIEnv *env, jclass cls) {
return (jboolean) Initialize();
}
extern "C" JNIEXPORT jboolean JNICALL Java_org_eclipse_fx_drift_internal_GL_destroy(JNIEnv *env, jclass cls) {
return (jboolean) Destroy();
}
extern "C" JNIEXPORT jlong JNICALL Java_org_eclipse_fx_drift_internal_GL_createContext(JNIEnv *env, jclass cls, jlong sharedContext, jint majorHint, jint minorHint) {
return (jlong) CreateContext((Context*) sharedContext, (int) majorHint, (int) minorHint);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_eclipse_fx_drift_internal_GL_createSharedCompatContext(JNIEnv *env, jclass cls, jlong sharedContext) {
return (jlong) CreateSharedCompatContext((Context*) sharedContext);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_eclipse_fx_drift_internal_GL_wrapContext(JNIEnv *env, jclass cls, jlong nativeContextHandle) {
return (jlong) WrapContext((jlong) nativeContextHandle);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_eclipse_fx_drift_internal_GL_getCurrentContext(JNIEnv *env, jclass cls) {
return (jlong) GetCurrentContext();
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_destroyContext(JNIEnv *env, jclass cls, jlong context) {
DestroyContext((Context*) context);
}
extern "C" JNIEXPORT jboolean JNICALL Java_org_eclipse_fx_drift_internal_GL_makeContextCurrent(JNIEnv *env, jclass cls, jlong context) {
return (jboolean) MakeContextCurrent((Context*) context);
}
extern "C" JNIEXPORT jboolean JNICALL Java_org_eclipse_fx_drift_internal_GL_isContextCurrent(JNIEnv *env, jclass cls, jlong context) {
return (jboolean) IsContextCurrent((Context*) context);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_eclipse_fx_drift_internal_GL_getNativeContextHandle(JNIEnv *env, jclass cls, jlong context) {
return (jlong) GetNativeContextHandle((Context*) context);
}
extern "C" JNIEXPORT jint JNICALL Java_org_eclipse_fx_drift_internal_GL_glGenTexture(JNIEnv *env, jclass cls) {
GLuint tex;
glGenTextures(1, &tex);
return (jint) tex;
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glDeleteTexture(JNIEnv *env, jclass cls, jint texture) {
GLuint tex = (GLuint) texture;
glDeleteTextures(1, &tex);
}
extern "C" JNIEXPORT jboolean JNICALL Java_org_eclipse_fx_drift_internal_GL_glIsTexture(JNIEnv *env, jclass cls, jint texture) {
GLuint tex = (GLuint) texture;
return (jboolean) glIsTexture(tex);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glBindTexture(JNIEnv *env, jclass cls, jint _target, jint _texture) {
GLenum target = (GLenum) _target;
GLuint texture = (GLuint) _texture;
glBindTexture(target, texture);
}
extern "C" JNIEXPORT jint JNICALL Java_org_eclipse_fx_drift_internal_GL_glGetError(JNIEnv *env, jclass cls) {
return (jint) glGetError();
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glBlitFramebuffer(JNIEnv *env, jclass cls, jint _srcX0, jint _srcY0, jint _srcX1, jint _srcY1, jint _dstX0, jint _dstY0, jint _dstX1, jint _dstY1, jint _mask, jint _filter) {
GLint srcX0 = (GLint) _srcX0;
GLint srcY0 = (GLint) _srcY0;
GLint srcX1 = (GLint) _srcX1;
GLint srcY1 = (GLint) _srcY1;
GLint dstX0 = (GLint) _dstX0;
GLint dstY0 = (GLint) _dstY0;
GLint dstX1 = (GLint) _dstX1;
GLint dstY1 = (GLint) _dstY1;
GLbitfield mask = (GLbitfield) _mask;
GLenum filter = (GLenum) _filter;
glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glTexImage2D(JNIEnv *env, jclass cls, jint _target, jint _level, jint _internalformat, jint _width, jint _height, jint _border, jint _format, jint _type, jlong _pPixels) {
GLenum target = (GLenum) _target;
GLint level = (GLint) _level;
GLint internalformat = (GLint) _internalformat;
GLsizei width = (GLsizei) _width;
GLsizei height = (GLsizei) _height;
GLint border = (GLint) _border;
GLenum format = (GLenum) _format;
GLenum type = (GLenum) _type;
void* pixels = (void*) _pPixels;
GLint tex;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex);
//std::cout << "TEXTURE_2D = " << tex << std::endl;
//std::cout << "glTexImage2D " << width << " x " << height << " @ " << pixels << std::endl;
//std::cout << std::flush;
glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glGetTexImage(JNIEnv *env, jclass cls, jint _target, jint _level, jint _format, jint _type, jlong _pPixels) {
GLenum target = (GLenum) _target;
GLint level = (GLint) _level;
GLenum format = (GLenum) _format;
GLenum type = (GLenum) _type;
void* pixels = (void*) _pPixels;
glGetTexImage(target, level, format, type, pixels);
}
extern "C" JNIEXPORT jint JNICALL Java_org_eclipse_fx_drift_internal_GL_glGenBuffer(JNIEnv *env, jclass cls) {
GLuint buffer;
glGenBuffers(1, &buffer);
return (jint) buffer;
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glDeleteBuffer(JNIEnv *env, jclass cls, jint _buffer) {
GLuint buffer = (GLuint) _buffer;
glDeleteBuffers(1, &buffer);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glBindBuffer(JNIEnv *env, jclass cls, jint _target, jint _buffer) {
GLenum target = (GLenum) _target;
GLuint buffer = (GLuint) _buffer;
glBindBuffer(target, buffer);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glBufferData(JNIEnv *env, jclass cls, jint _target, jint _size, jlong _pData, jint _usage) {
GLenum target = (GLenum) _target;
GLsizei size = (GLsizei) _size;
void* data = (void*) _pData;
GLenum usage = (GLenum) _usage;
glBufferData(target, size, data, usage);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_eclipse_fx_drift_internal_GL_glMapBuffer(JNIEnv *env, jclass cls, jint _target, jint _access) {
GLenum target = (GLenum) _target;
GLenum access = (GLenum) _access;
return (jlong) glMapBuffer(target, access);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glUnmapBuffer(JNIEnv *env, jclass cls, jint _target) {
GLenum target = (GLenum) _target;
glUnmapBuffer(target);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glClearColor(JNIEnv *env, jclass cls, jfloat _red, jfloat _green, jfloat _blue, jfloat _alpha) {
GLfloat red = (GLfloat) _red;
GLfloat green = (GLfloat) _green;
GLfloat blue = (GLfloat) _blue;
GLfloat alpha = (GLfloat) _alpha;
glClearColor(red, green, blue, alpha);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glClear(JNIEnv *env, jclass cls, jint _mask) {
GLbitfield mask = (GLbitfield) _mask;
glClear(mask);
}
extern "C" JNIEXPORT jint JNICALL Java_org_eclipse_fx_drift_internal_GL_glGenFramebuffer(JNIEnv *env, jclass cls) {
GLuint fb;
glGenFramebuffers(1, &fb);
return (jint) fb;
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glDeleteFramebuffer(JNIEnv *env, jclass cls, jint _framebuffer) {
GLuint framebuffer = (GLuint) _framebuffer;
glDeleteBuffers(1, &framebuffer);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glBindFramebuffer(JNIEnv *env, jclass cls, jint _target, jint _framebuffer) {
GLenum target = (GLenum) _target;
GLuint framebuffer = (GLuint) _framebuffer;
glBindFramebuffer(target, framebuffer);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glFramebufferTexture(JNIEnv *env, jclass cls, jint _target, jint _attachment, jint _texture, jint _level) {
GLenum target = (GLenum) _target;
GLenum attachment = (GLenum) _attachment;
GLuint texture = (GLuint) _texture;
GLuint level = (GLuint) _level;
glFramebufferTexture(target, attachment, texture, level);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glPixelStorei(JNIEnv *env, jclass cls, jint _pname, jint _param) {
GLenum pname = (GLenum) _pname;
GLint param = (GLint) _param;
glPixelStorei(pname, param);
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glPixelStoref(JNIEnv *env, jclass cls, jint _pname, jfloat _param) {
GLenum pname = (GLenum) _pname;
GLfloat param = (GLfloat) _param;
glPixelStoref(pname, param);
}
extern "C" JNIEXPORT jint JNICALL Java_org_eclipse_fx_drift_internal_GL_glGetInteger(JNIEnv *env, jclass cls, jint _pname, jfloat _param) {
GLenum pname = (GLenum) _pname;
GLint param;
glGetIntegerv(pname, ¶m);
return (jint) param;
}
extern "C" JNIEXPORT jfloat JNICALL Java_org_eclipse_fx_drift_internal_GL_glGetFloat(JNIEnv *env, jclass cls, jint _pname, jfloat _param) {
GLenum pname = (GLenum) _pname;
GLfloat param;
glGetFloatv(pname, ¶m);
return (jfloat) param;
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glFlush(JNIEnv *env, jclass cls) {
glFlush();
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glFinish(JNIEnv *env, jclass cls) {
glFinish();
}
extern "C" JNIEXPORT jlong JNICALL Java_org_eclipse_fx_drift_internal_GL_glCreateFence(JNIEnv *env, jclass cls) {
GLsync fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
return (jlong) fence;
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glDeleteSync(JNIEnv* env, jclass cls, jlong sync) {
GLsync fence = (GLsync) sync;
glDeleteSync(fence);
}
extern "C" JNIEXPORT jint JNICALL Java_org_eclipse_fx_drift_internal_GL_glClientWaitSync(JNIEnv* env, jclass cls, jlong sync, long timeout) {
GLsync fence = (GLsync) sync;
GLuint64 tout = (GLuint64) timeout;
GLenum result = glClientWaitSync(fence, GL_SYNC_FLUSH_COMMANDS_BIT, tout);
return (jint) result;
}
extern "C" JNIEXPORT void JNICALL Java_org_eclipse_fx_drift_internal_GL_glWaitSync(JNIEnv* env, jclass cls, jlong sync) {
GLsync fence = (GLsync) sync;
glWaitSync(fence, 0, GL_TIMEOUT_IGNORED);
}