EglEnv.java
3.63 KB
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
package com.sw.laryngoscope.imageToVideo;
import android.opengl.EGL14;
import android.opengl.EGLConfig;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.EGLExt;
import android.opengl.EGLSurface;
import android.util.Log;
import android.view.Surface;
public final class EglEnv {
private EGLDisplay eglDisplay= EGL14.EGL_NO_DISPLAY;
private EGLContext eglContext = EGL14.EGL_NO_CONTEXT;
private EGLSurface eglSurface;
private EGLConfig eglConfig;
private final int width;
private final int height;
private int mGlVersion = -1;
public final EglEnv setUpEnv() {
this.eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
int[] version = new int[2];
if(!EGL14.eglInitialize(this.eglDisplay, version, 0, version, 1)) {
}
int[] attribs = new int[]{ EGL14.EGL_BUFFER_SIZE, 32,
EGL14.EGL_ALPHA_SIZE, 8,
EGL14.EGL_BLUE_SIZE, 8,
EGL14.EGL_GREEN_SIZE, 8,
EGL14.EGL_RED_SIZE, 8,
EGL14.EGL_RENDERABLE_TYPE,
EGL14.EGL_OPENGL_ES2_BIT,
EGL14.EGL_SURFACE_TYPE,
EGL14.EGL_WINDOW_BIT,
EGL14.EGL_NONE};
EGLConfig[] configs = new EGLConfig[1];
int[] numConfigs = new int[1];
if(!EGL14.eglChooseConfig(this.eglDisplay, attribs, 0, configs, 0, configs.length, numConfigs, 0)) {
}
this.eglConfig = configs[0];
int[] attributes = new int[]{EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE};
this.eglContext = EGL14.eglCreateContext(this.eglDisplay, this.eglConfig, EGL14.EGL_NO_CONTEXT, attributes, 0);
return this;
}
// public final void buildOffScreenSurface() {
// int[] pbufferAttributes = new int[]{12375, this.width, 12374, this.height, 12344};
// this.eglSurface = EGL14.eglCreatePbufferSurface(this.eglDisplay, this.eglConfig, pbufferAttributes, 0);
//
//
// this.makeCurrent();
// }
public final void buildWindowSurface( Surface surface) {
int[] format = new int[1];
if(!EGL14.eglGetConfigAttrib(this.eglDisplay, this.eglConfig, EGL14.EGL_NATIVE_VISUAL_ID, format, 0)) {
}
if (eglSurface != EGL14.EGL_NO_SURFACE) {
}
int[] surfaceAttribs = new int[]{EGL14.EGL_NONE};
this.eglSurface = EGL14.eglCreateWindowSurface(this.eglDisplay, this.eglConfig, surface, surfaceAttribs, 0);
this.makeCurrent();
}
private final void makeCurrent() {
Log.d(this.getClass().getName(), " egl make current ");
if(!EGL14.eglMakeCurrent(this.eglDisplay, this.eglSurface, this.eglSurface, this.eglContext)) {
}
}
public final void setPresentationTime(long nsecs) {
EGLExt.eglPresentationTimeANDROID(this.eglDisplay, this.eglSurface, nsecs);
}
public final boolean swapBuffers() {
boolean result = EGL14.eglSwapBuffers(this.eglDisplay, this.eglSurface);
return result;
}
public final void relase() {
EGL14.eglMakeCurrent(this.eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
EGL14.eglDestroySurface(this.eglDisplay, this.eglSurface);
EGL14.eglDestroyContext(this.eglDisplay, this.eglContext);
EGL14.eglReleaseThread();
EGL14.eglTerminate(this.eglDisplay);
this.eglSurface = EGL14.EGL_NO_SURFACE;
this.eglContext = EGL14.EGL_NO_CONTEXT;
this.eglDisplay = EGL14.EGL_NO_DISPLAY;
}
public EglEnv(int width, int height) {
this.width = width;
this.height = height;
this.eglDisplay = EGL14.EGL_NO_DISPLAY;
this.eglContext = EGL14.EGL_NO_CONTEXT;
this.eglSurface = EGL14.EGL_NO_SURFACE;
}
}