fork download
  1. package com.example.glsample;
  2.  
  3. import java.util.concurrent.LinkedBlockingQueue;
  4.  
  5. import javax.microedition.khronos.egl.EGL10;
  6. import javax.microedition.khronos.egl.EGLConfig;
  7. import javax.microedition.khronos.egl.EGLContext;
  8. import javax.microedition.khronos.egl.EGLDisplay;
  9. import javax.microedition.khronos.egl.EGLSurface;
  10.  
  11. import android.annotation.TargetApi;
  12. import android.app.Activity;
  13. import android.opengl.EGL14;
  14. import android.opengl.GLES10;
  15. import android.os.Build;
  16. import android.os.Bundle;
  17. import android.view.SurfaceHolder;
  18.  
  19. @TargetApi(17)
  20. public class MyActivity extends Activity implements SurfaceHolder.Callback2 {
  21. private EGL10 mEGL;
  22. private EGLDisplay mDisplay;
  23. private EGLContext mRendererContext;
  24. private EGLContext mWorkerContext;
  25. private EGLSurface mRendererSurface;
  26. private EGLSurface mWorkerSurface;
  27. private LinkedBlockingQueue<Runnable> mRendererQueue;
  28. private LinkedBlockingQueue<Runnable> mWorkerQueue;
  29. private MyGLThread mRendererThread;
  30. private MyGLThread mWorkerThread;
  31.  
  32. @Override
  33. protected void onCreate(Bundle savedInstanceState) {
  34. super.onCreate(savedInstanceState);
  35. getWindow().takeSurface(this);
  36. }
  37.  
  38. @Override
  39. public void surfaceCreated(SurfaceHolder holder) {
  40. mEGL = (EGL10) EGLContext.getEGL();
  41.  
  42. mDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
  43.  
  44. int[] versions = new int[2];
  45. mEGL.eglInitialize(mDisplay, versions);
  46.  
  47. EGLConfig[] configs = new EGLConfig[1];
  48. int[] numConfigs = new int[1];
  49. int[] configAttrs = { EGL10.EGL_RED_SIZE, 8, EGL10.EGL_GREEN_SIZE, 8,
  50. EGL10.EGL_BLUE_SIZE, 8, EGL10.EGL_DEPTH_SIZE, 16,
  51. EGL10.EGL_NONE };
  52. mEGL.eglChooseConfig(mDisplay, configAttrs, configs, 1, numConfigs);
  53. EGLConfig config = configs[0];
  54.  
  55. int[] windowSurfaceAttrs = { EGL10.EGL_NONE };
  56. mRendererSurface = mEGL.eglCreateWindowSurface(mDisplay, config,
  57. holder.getSurface(), windowSurfaceAttrs);
  58.  
  59. int[] pbufferSurfaceAttrs = { EGL10.EGL_NONE };
  60. mWorkerSurface = mEGL.eglCreatePbufferSurface(mDisplay, config,
  61. pbufferSurfaceAttrs);
  62.  
  63. int[] contextAttrs = { EGL10.EGL_NONE };
  64. mRendererContext = mEGL.eglCreateContext(mDisplay, config,
  65. EGL10.EGL_NO_CONTEXT, contextAttrs);
  66. mWorkerContext = mEGL.eglCreateContext(mDisplay, config,
  67. mRendererContext, contextAttrs);
  68.  
  69. mRendererQueue = new LinkedBlockingQueue<Runnable>();
  70. mWorkerQueue = new LinkedBlockingQueue<Runnable>();
  71.  
  72. mRendererThread = new MyGLThread(mEGL, mDisplay, mRendererSurface,
  73. mRendererContext, mRendererQueue);
  74. mRendererThread.start();
  75.  
  76. mWorkerThread = new MyGLThread(mEGL, mDisplay, mWorkerSurface,
  77. mWorkerContext, mWorkerQueue);
  78. mWorkerThread.start();
  79.  
  80. mRendererQueue.add(new Runnable() {
  81. @Override
  82. public void run() {
  83. drawFrame();
  84. mRendererQueue.add(this);
  85. mEGL.eglSwapBuffers(mDisplay, mRendererSurface);
  86. }
  87. });
  88. }
  89.  
  90. @Override
  91. public void surfaceChanged(SurfaceHolder holder, int format, int width,
  92. int height) {
  93. }
  94.  
  95. @Override
  96. public void surfaceRedrawNeeded(SurfaceHolder holder) {
  97. }
  98.  
  99. @Override
  100. public void surfaceDestroyed(SurfaceHolder holder) {
  101. mRendererThread.quit();
  102. mWorkerThread.quit();
  103. mEGL.eglDestroyContext(mDisplay, mRendererContext);
  104. mEGL.eglDestroyContext(mDisplay, mWorkerContext);
  105. mEGL.eglDestroySurface(mDisplay, mRendererSurface);
  106. mEGL.eglDestroySurface(mDisplay, mWorkerSurface);
  107. mEGL.eglTerminate(mDisplay);
  108. }
  109.  
  110. void drawFrame() {
  111. GLES10.glClearColor(0, 0, 1, 1);
  112. GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT | GLES10.GL_DEPTH_BUFFER_BIT);
  113. // ...
  114. }
  115. }
  116.  
  117. class MyGLThread extends Thread {
  118. private EGL10 mEGL;
  119. private EGLDisplay mDisplay;
  120. private EGLSurface mSurface;
  121. private EGLContext mContext;
  122. private LinkedBlockingQueue<Runnable> mQueue;
  123. private boolean quit;
  124.  
  125. MyGLThread(EGL10 egl, EGLDisplay display, EGLSurface surface,
  126. EGLContext context, LinkedBlockingQueue<Runnable> queue) {
  127. this.mEGL = egl;
  128. this.mDisplay = display;
  129. this.mSurface = surface;
  130. this.mContext = context;
  131. this.mQueue = queue;
  132. }
  133.  
  134. void quit() {
  135. quit = true;
  136. interrupt();
  137. try {
  138. join();
  139. } catch (InterruptedException e) {
  140. throw new AssertionError(e);
  141. }
  142. }
  143.  
  144. @Override
  145. public void run() {
  146. try {
  147. mEGL.eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
  148. while (!quit) {
  149. mQueue.take().run();
  150. }
  151. } catch (InterruptedException e) {
  152. if (!quit) {
  153. throw new AssertionError(e);
  154. }
  155. } finally {
  156. mEGL.eglMakeCurrent(mDisplay, EGL10.EGL_NO_SURFACE,
  157. EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
  158. if (Build.VERSION.SDK_INT >= 17) {
  159. EGL14.eglReleaseThread();
  160. }
  161. }
  162. }
  163. }
  164.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:20: error: class MyActivity is public, should be declared in a file named MyActivity.java
public class MyActivity extends Activity implements SurfaceHolder.Callback2 {
       ^
Main.java:5: error: package javax.microedition.khronos.egl does not exist
import javax.microedition.khronos.egl.EGL10;
                                     ^
Main.java:6: error: package javax.microedition.khronos.egl does not exist
import javax.microedition.khronos.egl.EGLConfig;
                                     ^
Main.java:7: error: package javax.microedition.khronos.egl does not exist
import javax.microedition.khronos.egl.EGLContext;
                                     ^
Main.java:8: error: package javax.microedition.khronos.egl does not exist
import javax.microedition.khronos.egl.EGLDisplay;
                                     ^
Main.java:9: error: package javax.microedition.khronos.egl does not exist
import javax.microedition.khronos.egl.EGLSurface;
                                     ^
Main.java:11: error: package android.annotation does not exist
import android.annotation.TargetApi;
                         ^
Main.java:12: error: package android.app does not exist
import android.app.Activity;
                  ^
Main.java:13: error: package android.opengl does not exist
import android.opengl.EGL14;
                     ^
Main.java:14: error: package android.opengl does not exist
import android.opengl.GLES10;
                     ^
Main.java:15: error: package android.os does not exist
import android.os.Build;
                 ^
Main.java:16: error: package android.os does not exist
import android.os.Bundle;
                 ^
Main.java:17: error: package android.view does not exist
import android.view.SurfaceHolder;
                   ^
Main.java:20: error: cannot find symbol
public class MyActivity extends Activity implements SurfaceHolder.Callback2 {
                                ^
  symbol: class Activity
Main.java:20: error: package SurfaceHolder does not exist
public class MyActivity extends Activity implements SurfaceHolder.Callback2 {
                                                                 ^
Main.java:19: error: cannot find symbol
@TargetApi(17)
 ^
  symbol: class TargetApi
Main.java:21: error: cannot find symbol
	private EGL10 mEGL;
	        ^
  symbol:   class EGL10
  location: class MyActivity
Main.java:22: error: cannot find symbol
	private EGLDisplay mDisplay;
	        ^
  symbol:   class EGLDisplay
  location: class MyActivity
Main.java:23: error: cannot find symbol
	private EGLContext mRendererContext;
	        ^
  symbol:   class EGLContext
  location: class MyActivity
Main.java:24: error: cannot find symbol
	private EGLContext mWorkerContext;
	        ^
  symbol:   class EGLContext
  location: class MyActivity
Main.java:25: error: cannot find symbol
	private EGLSurface mRendererSurface;
	        ^
  symbol:   class EGLSurface
  location: class MyActivity
Main.java:26: error: cannot find symbol
	private EGLSurface mWorkerSurface;
	        ^
  symbol:   class EGLSurface
  location: class MyActivity
Main.java:33: error: cannot find symbol
	protected void onCreate(Bundle savedInstanceState) {
	                        ^
  symbol:   class Bundle
  location: class MyActivity
Main.java:39: error: cannot find symbol
	public void surfaceCreated(SurfaceHolder holder) {
	                           ^
  symbol:   class SurfaceHolder
  location: class MyActivity
Main.java:91: error: cannot find symbol
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
	                           ^
  symbol:   class SurfaceHolder
  location: class MyActivity
Main.java:96: error: cannot find symbol
	public void surfaceRedrawNeeded(SurfaceHolder holder) {
	                                ^
  symbol:   class SurfaceHolder
  location: class MyActivity
Main.java:100: error: cannot find symbol
	public void surfaceDestroyed(SurfaceHolder holder) {
	                             ^
  symbol:   class SurfaceHolder
  location: class MyActivity
Main.java:118: error: cannot find symbol
	private EGL10 mEGL;
	        ^
  symbol:   class EGL10
  location: class MyGLThread
Main.java:119: error: cannot find symbol
	private EGLDisplay mDisplay;
	        ^
  symbol:   class EGLDisplay
  location: class MyGLThread
Main.java:120: error: cannot find symbol
	private EGLSurface mSurface;
	        ^
  symbol:   class EGLSurface
  location: class MyGLThread
Main.java:121: error: cannot find symbol
	private EGLContext mContext;
	        ^
  symbol:   class EGLContext
  location: class MyGLThread
Main.java:125: error: cannot find symbol
	MyGLThread(EGL10 egl, EGLDisplay display, EGLSurface surface,
	           ^
  symbol:   class EGL10
  location: class MyGLThread
Main.java:125: error: cannot find symbol
	MyGLThread(EGL10 egl, EGLDisplay display, EGLSurface surface,
	                      ^
  symbol:   class EGLDisplay
  location: class MyGLThread
Main.java:125: error: cannot find symbol
	MyGLThread(EGL10 egl, EGLDisplay display, EGLSurface surface,
	                                          ^
  symbol:   class EGLSurface
  location: class MyGLThread
Main.java:126: error: cannot find symbol
			EGLContext context, LinkedBlockingQueue<Runnable> queue) {
			^
  symbol:   class EGLContext
  location: class MyGLThread
Main.java:34: error: cannot find symbol
		super.onCreate(savedInstanceState);
		^
  symbol:   variable super
  location: class MyActivity
Main.java:35: error: cannot find symbol
		getWindow().takeSurface(this);
		^
  symbol:   method getWindow()
  location: class MyActivity
Main.java:32: error: method does not override or implement a method from a supertype
	@Override
	^
Main.java:40: error: cannot find symbol
		mEGL = (EGL10) EGLContext.getEGL();
		        ^
  symbol:   class EGL10
  location: class MyActivity
Main.java:40: error: cannot find symbol
		mEGL = (EGL10) EGLContext.getEGL();
		               ^
  symbol:   variable EGLContext
  location: class MyActivity
Main.java:42: error: cannot find symbol
		mDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
		                              ^
  symbol:   variable EGL10
  location: class MyActivity
Main.java:47: error: cannot find symbol
		EGLConfig[] configs = new EGLConfig[1];
		^
  symbol:   class EGLConfig
  location: class MyActivity
Main.java:47: error: cannot find symbol
		EGLConfig[] configs = new EGLConfig[1];
		                          ^
  symbol:   class EGLConfig
  location: class MyActivity
Main.java:49: error: cannot find symbol
		int[] configAttrs = { EGL10.EGL_RED_SIZE, 8, EGL10.EGL_GREEN_SIZE, 8,
		                      ^
  symbol:   variable EGL10
  location: class MyActivity
Main.java:49: error: cannot find symbol
		int[] configAttrs = { EGL10.EGL_RED_SIZE, 8, EGL10.EGL_GREEN_SIZE, 8,
		                                             ^
  symbol:   variable EGL10
  location: class MyActivity
Main.java:50: error: cannot find symbol
				EGL10.EGL_BLUE_SIZE, 8, EGL10.EGL_DEPTH_SIZE, 16,
				^
  symbol:   variable EGL10
  location: class MyActivity
Main.java:50: error: cannot find symbol
				EGL10.EGL_BLUE_SIZE, 8, EGL10.EGL_DEPTH_SIZE, 16,
				                        ^
  symbol:   variable EGL10
  location: class MyActivity
Main.java:51: error: cannot find symbol
				EGL10.EGL_NONE };
				^
  symbol:   variable EGL10
  location: class MyActivity
Main.java:53: error: cannot find symbol
		EGLConfig config = configs[0];
		^
  symbol:   class EGLConfig
  location: class MyActivity
Main.java:55: error: cannot find symbol
		int[] windowSurfaceAttrs = { EGL10.EGL_NONE };
		                             ^
  symbol:   variable EGL10
  location: class MyActivity
Main.java:59: error: cannot find symbol
		int[] pbufferSurfaceAttrs = { EGL10.EGL_NONE };
		                              ^
  symbol:   variable EGL10
  location: class MyActivity
Main.java:63: error: cannot find symbol
		int[] contextAttrs = { EGL10.EGL_NONE };
		                       ^
  symbol:   variable EGL10
  location: class MyActivity
Main.java:65: error: cannot find symbol
				EGL10.EGL_NO_CONTEXT, contextAttrs);
				^
  symbol:   variable EGL10
  location: class MyActivity
Main.java:38: error: method does not override or implement a method from a supertype
	@Override
	^
Main.java:90: error: method does not override or implement a method from a supertype
	@Override
	^
Main.java:95: error: method does not override or implement a method from a supertype
	@Override
	^
Main.java:99: error: method does not override or implement a method from a supertype
	@Override
	^
Main.java:111: error: cannot find symbol
		GLES10.glClearColor(0, 0, 1, 1);
		^
  symbol:   variable GLES10
  location: class MyActivity
Main.java:112: error: cannot find symbol
		GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT | GLES10.GL_DEPTH_BUFFER_BIT);
		               ^
  symbol:   variable GLES10
  location: class MyActivity
Main.java:112: error: cannot find symbol
		GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT | GLES10.GL_DEPTH_BUFFER_BIT);
		                                            ^
  symbol:   variable GLES10
  location: class MyActivity
Main.java:112: error: cannot find symbol
		GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT | GLES10.GL_DEPTH_BUFFER_BIT);
		^
  symbol:   variable GLES10
  location: class MyActivity
Main.java:156: error: cannot find symbol
			mEGL.eglMakeCurrent(mDisplay, EGL10.EGL_NO_SURFACE,
			                              ^
  symbol:   variable EGL10
  location: class MyGLThread
Main.java:157: error: cannot find symbol
					EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
					^
  symbol:   variable EGL10
  location: class MyGLThread
Main.java:157: error: cannot find symbol
					EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
					                      ^
  symbol:   variable EGL10
  location: class MyGLThread
Main.java:158: error: package Build does not exist
			if (Build.VERSION.SDK_INT >= 17) {
			         ^
Main.java:159: error: cannot find symbol
				EGL14.eglReleaseThread();
				^
  symbol:   variable EGL14
  location: class MyGLThread
66 errors
stdout
Standard output is empty