android.opengl.GLException Java Examples
The following examples show how to use
android.opengl.GLException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EglUtil.java From Mp4Composer-android with MIT License | 6 votes |
public static int createProgram(final int vertexShader, final int pixelShader) throws GLException { final int program = glCreateProgram(); if (program == 0) { throw new RuntimeException("Could not create program"); } GLES20.glAttachShader(program, vertexShader); GLES20.glAttachShader(program, pixelShader); GLES20.glLinkProgram(program); final int[] linkStatus = new int[1]; GLES20.glGetProgramiv(program, GL_LINK_STATUS, linkStatus, 0); if (linkStatus[0] != GL_TRUE) { GLES20.glDeleteProgram(program); throw new RuntimeException("Could not link program"); } return program; }
Example #2
Source File: EglUtil.java From SimpleVideoEdit with Apache License 2.0 | 6 votes |
public static int createProgram(final int vertexShader, final int pixelShader) throws GLException { // create empty OpenGL ES Program, store the id in program final int program = glCreateProgram(); if (program == 0) { throw new RuntimeException("Could not create program"); } // add the vertex shader to program GLES20.glAttachShader(program, vertexShader); // add the fragment shader to program GLES20.glAttachShader(program, pixelShader); // creates OpenGL ES program executables GLES20.glLinkProgram(program); final int[] linkStatus = new int[1]; GLES20.glGetProgramiv(program, GL_LINK_STATUS, linkStatus, 0); if (linkStatus[0] != GL_TRUE) { GLES20.glDeleteProgram(program); throw new RuntimeException("Could not link program"); } return program; }
Example #3
Source File: Shader.java From Tanks with MIT License | 6 votes |
public void validate() { if (!GameContext.debuggable) return; int[] result = new int[1]; GLES20.glValidateProgram(programHandle); GLES20.glGetProgramiv(programHandle, GLES20.GL_VALIDATE_STATUS, result, 0); if (result[0] == 0) { String message = !GLES20.glIsProgram(programHandle) ? "Program handle deprecated!" : "Program do not validated!"; throw new GLException(result[0], message); } }
Example #4
Source File: Renderer.java From Tanks with MIT License | 6 votes |
private static void draw(RendererContext context, ArrayList<IRenderable> renderables) { for (IRenderable renderable : renderables) { if (!renderable.isVisible()) continue; Shader.setShader(renderable.getShaderId()); renderable.draw(context); int error; if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) { Class<?> renderableClass = renderable.getClass(); String message = String.format("Error after %s draw call", renderableClass.getName()); throw new GLException(error, message); } } }
Example #5
Source File: EglUtil.java From CameraRecorder-android with MIT License | 6 votes |
public static int createProgram(final int vertexShader, final int pixelShader) throws GLException { final int program = glCreateProgram(); if (program == 0) { throw new RuntimeException("Could not create program"); } GLES20.glAttachShader(program, vertexShader); GLES20.glAttachShader(program, pixelShader); GLES20.glLinkProgram(program); final int[] linkStatus = new int[1]; GLES20.glGetProgramiv(program, GL_LINK_STATUS, linkStatus, 0); if (linkStatus[0] != GL_TRUE) { GLES20.glDeleteProgram(program); throw new RuntimeException("Could not link program"); } return program; }
Example #6
Source File: EglUtil.java From GPUVideo-android with MIT License | 6 votes |
public static int createProgram(final int vertexShader, final int pixelShader) throws GLException { final int program = glCreateProgram(); if (program == 0) { throw new RuntimeException("Could not create program"); } GLES20.glAttachShader(program, vertexShader); GLES20.glAttachShader(program, pixelShader); GLES20.glLinkProgram(program); final int[] linkStatus = new int[1]; GLES20.glGetProgramiv(program, GL_LINK_STATUS, linkStatus, 0); if (linkStatus[0] != GL_TRUE) { GLES20.glDeleteProgram(program); throw new RuntimeException("Could not link program"); } return program; }
Example #7
Source File: OpenGLUtil.java From android-openGL-canvas with Apache License 2.0 | 5 votes |
public static Bitmap createBitmapFromGLSurface(int x, int y, int w, int h, int glHeight) throws OutOfMemoryError { int bitmapBuffer[] = new int[w * h]; int bitmapSource[] = new int[w * h]; IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer); intBuffer.position(0); try { GLES11.glReadPixels(x, glHeight - h - y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, intBuffer); int offset1, offset2; for (int i = 0; i < h; i++) { offset1 = i * w; offset2 = (h - i - 1) * w; for (int j = 0; j < w; j++) { int texturePixel = bitmapBuffer[offset1 + j]; int blue = (texturePixel >> 16) & 0xff; int red = (texturePixel << 16) & 0x00ff0000; int pixel = (texturePixel & 0xff00ff00) | red | blue; bitmapSource[offset2 + j] = pixel; } } } catch (GLException e) { return null; } return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888); }
Example #8
Source File: Shader.java From Tanks with MIT License | 5 votes |
private int compileShader(int type, String path) { try { // Load shader source InputStream stream = GameContext.context.getAssets().open(path); int size = stream.available(); byte[] buffer = new byte[size]; int readCount = stream.read(buffer); if (readCount != size) throw new IOException("File has been read not fully: " + path); String source = new String(buffer); stream.close(); // Compile shader int shaderHandle = GLES20.glCreateShader(type); GLES20.glShaderSource(shaderHandle, source); GLES20.glCompileShader(shaderHandle); // Check for errors int[] compiled = new int[1]; GLES20.glGetShaderiv(shaderHandle, GLES20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == 0) { String error = GLES20.glGetShaderInfoLog(shaderHandle); GLES20.glDeleteShader(shaderHandle); throw new GLException(compiled[0], error); } return shaderHandle; } catch(IOException e) { throw new RuntimeException(e); } }
Example #9
Source File: GeometrySource.java From Tanks with MIT License | 5 votes |
private static int loadGeometry(final FloatBuffer buffer) { ResultRunnable<Integer> runnable = new ResultRunnable<Integer>() { @Override protected Integer onRun() { int error; int[] buffers = new int[1]; GLES20.glGenBuffers(1, buffers, 0); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error, Integer.toString(error)); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error, Integer.toString(error)); GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, buffer.capacity() * 4, buffer, GLES20.GL_STATIC_DRAW); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error, Integer.toString(error)); return buffers[0]; } }; GameContext.glThread.sendEvent(runnable); return runnable.getResult(); }
Example #10
Source File: GSYVideoGLViewBaseRender.java From GSYVideoPlayer with Apache License 2.0 | 5 votes |
/** * 创建bitmap截图 */ protected Bitmap createBitmapFromGLSurface(int x, int y, int w, int h, GL10 gl) { int bitmapBuffer[] = new int[w * h]; int bitmapSource[] = new int[w * h]; IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer); intBuffer.position(0); try { gl.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10. GL_UNSIGNED_BYTE, intBuffer); int offset1, offset2; for (int i = 0; i < h; i++) { offset1 = i * w; offset2 = (h - i - 1) * w; for (int j = 0; j < w; j++) { int texturePixel = bitmapBuffer[offset1 + j]; int blue = (texturePixel >> 16) & 0xff; int red = (texturePixel << 16) & 0x00ff0000; int pixel = (texturePixel & 0xff00ff00) | red | blue; bitmapSource[offset2 + j] = pixel; } } } catch (GLException e) { return null; } if (mHighShot) { return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888); } else { return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.RGB_565); } }
Example #11
Source File: EGLLogWrapper.java From android-openGL-canvas with Apache License 2.0 | 5 votes |
private void checkError() { int eglError; if ((eglError = mEgl10.eglGetError()) != EGL_SUCCESS) { String errorMessage = "eglError: " + getErrorString(eglError); logLine(errorMessage); if (mCheckError) { throw new GLException(eglError, errorMessage); } } }
Example #12
Source File: EGLLogWrapper.java From DanDanPlayForAndroid with MIT License | 5 votes |
private void checkError() { int eglError; if ((eglError = mEgl10.eglGetError()) != EGL_SUCCESS) { String errorMessage = "eglError: " + getErrorString(eglError); logLine(errorMessage); if (mCheckError) { throw new GLException(eglError, errorMessage); } } }
Example #13
Source File: BaseCameraActivity.java From CameraRecorder-android with MIT License | 5 votes |
private Bitmap createBitmapFromGLSurface(int w, int h, GL10 gl) { int bitmapBuffer[] = new int[w * h]; int bitmapSource[] = new int[w * h]; IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer); intBuffer.position(0); try { gl.glReadPixels(0, 0, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, intBuffer); int offset1, offset2, texturePixel, blue, red, pixel; for (int i = 0; i < h; i++) { offset1 = i * w; offset2 = (h - i - 1) * w; for (int j = 0; j < w; j++) { texturePixel = bitmapBuffer[offset1 + j]; blue = (texturePixel >> 16) & 0xff; red = (texturePixel << 16) & 0x00ff0000; pixel = (texturePixel & 0xff00ff00) | red | blue; bitmapSource[offset2 + j] = pixel; } } } catch (GLException e) { Log.e("CreateBitmap", "createBitmapFromGLSurface: " + e.getMessage(), e); return null; } return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888); }
Example #14
Source File: BitmapUtil.java From PhotoEditor with MIT License | 5 votes |
/** * Save filter bitmap from {@link ImageFilterView} * * @param glSurfaceView surface view on which is image is drawn * @param gl open gl source to read pixels from {@link GLSurfaceView} * @return save bitmap * @throws OutOfMemoryError error when system is out of memory to load and save bitmap */ static Bitmap createBitmapFromGLSurface(GLSurfaceView glSurfaceView, GL10 gl) throws OutOfMemoryError { int x = 0, y = 0; int w = glSurfaceView.getWidth(); int h = glSurfaceView.getHeight(); int bitmapBuffer[] = new int[w * h]; int bitmapSource[] = new int[w * h]; IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer); intBuffer.position(0); try { gl.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, intBuffer); int offset1, offset2; for (int i = 0; i < h; i++) { offset1 = i * w; offset2 = (h - i - 1) * w; for (int j = 0; j < w; j++) { int texturePixel = bitmapBuffer[offset1 + j]; int blue = (texturePixel >> 16) & 0xff; int red = (texturePixel << 16) & 0x00ff0000; int pixel = (texturePixel & 0xff00ff00) | red | blue; bitmapSource[offset2 + j] = pixel; } } } catch (GLException e) { return null; } return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888); }
Example #15
Source File: BaseCameraActivity.java From GPUVideo-android with MIT License | 5 votes |
private Bitmap createBitmapFromGLSurface(int w, int h, GL10 gl) { int bitmapBuffer[] = new int[w * h]; int bitmapSource[] = new int[w * h]; IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer); intBuffer.position(0); try { gl.glReadPixels(0, 0, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, intBuffer); int offset1, offset2, texturePixel, blue, red, pixel; for (int i = 0; i < h; i++) { offset1 = i * w; offset2 = (h - i - 1) * w; for (int j = 0; j < w; j++) { texturePixel = bitmapBuffer[offset1 + j]; blue = (texturePixel >> 16) & 0xff; red = (texturePixel << 16) & 0x00ff0000; pixel = (texturePixel & 0xff00ff00) | red | blue; bitmapSource[offset2 + j] = pixel; } } } catch (GLException e) { Log.e("CreateBitmap", "createBitmapFromGLSurface: " + e.getMessage(), e); return null; } return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888); }
Example #16
Source File: OrientationView.java From PanoramaGL with Apache License 2.0 | 4 votes |
@Override public final void onSurfaceCreated(GL10 unused, EGLConfig config) { // Set up shaders int vertexShader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER); GLES20.glShaderSource(vertexShader, vertexShaderCode); GLES20.glCompileShader(vertexShader); int fragmentShader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER); GLES20.glShaderSource(fragmentShader, fragmentShaderCode); GLES20.glCompileShader(fragmentShader); program = GLES20.glCreateProgram(); GLES20.glAttachShader(program, vertexShader); GLES20.glAttachShader(program, fragmentShader); GLES20.glLinkProgram(program); int[] linkStatus = new int[1]; GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0); if (linkStatus[0] != GLES20.GL_TRUE) { throw new GLException(linkStatus[0], "Unable to create shader program: " + GLES20.glGetProgramInfoLog(program)); } // Set up geometry // 16 lines * 2 points * XYZ float[] boxVertexData = { // X-aligned lines of length 4 -2, -1, -3, 2, -1, -3, -2, -1, 3, 2, -1, 3, -2, 1, -3, 2, 1, -3, -2, 1, 3, 2, 1, 3, // Y-aligned lines of length 2 -2, -1, -3, -2, 1, -3, -2, -1, 3, -2, 1, 3, 2, -1, -3, 2, 1, -3, 2, -1, 3, 2, 1, 3, // Z-aligned lines of length 6 -2, -1, -3, -2, -1, 3, -2, 1, -3, -2, 1, 3, 2, -1, -3, 2, -1, 3, 2, 1, -3, 2, 1, 3, // Trackpad diamond -1, 1, -1, 0, 1, 0, 0, 1, 0, 1, 1, -1, 1, 1, -1, 0, 1, -3, 0, 1, -3, -1, 1, -1, }; ByteBuffer buffer = ByteBuffer.allocateDirect(boxVertexData.length * 4); buffer.order(ByteOrder.nativeOrder()); boxVertices = buffer.asFloatBuffer(); boxVertices.put(boxVertexData); boxVertices.position(0); // The XYZ lines are RGB in the positive direction and black in the negative direction. // 16 lines * 2 points * RGBA float[] boxColorData = { // X-aligned lines 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, // Y-aligned lines 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, // Z-aligned lines 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, // Trackpad 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, }; buffer = ByteBuffer.allocateDirect(boxColorData.length * 4); buffer.order(ByteOrder.nativeOrder()); boxColors = buffer.asFloatBuffer(); boxColors.put(boxColorData); boxColors.position(0); }
Example #17
Source File: FrameBufferSource.java From Tanks with MIT License | 4 votes |
private FrameBuffer build() { ResultRunnable<FrameBuffer> runnable = new ResultRunnable<FrameBuffer>() { @Override protected FrameBuffer onRun() { int width = (int) Renderer.getWidth(); int height = (int) Renderer.getHeight(); int[] renderTextureIds = new int[1]; GLES20.glGenTextures(1, renderTextureIds, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTextureIds[0]); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); int[] frameBufferIds = new int[1]; GLES20.glGenFramebuffers(1, frameBufferIds, 0); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBufferIds[0]); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTextureIds[0], 0); int[] depthTextureIds = new int[1]; GLES20.glGenRenderbuffers(1, depthTextureIds, 0); GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthTextureIds[0]); GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height); GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthTextureIds[0]); // check FBO status int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER); if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) throw new GLException(status, "GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO"); return new FrameBuffer(name, frameBufferIds[0], depthTextureIds[0], renderTextureIds[0]); } }; GameContext.glThread.sendEvent(runnable); return runnable.getResult(); }
Example #18
Source File: FileTextureSource.java From Tanks with MIT License | 4 votes |
private int loadTexture() { ResultRunnable<Integer> runnable = new ResultRunnable<Integer>() { @Override protected Integer onRun() { try { String fileName = getTextureFileName(name); InputStream stream = GameContext.context.getAssets().open(fileName); Bitmap bitmap = BitmapFactory.decodeStream(stream); stream.close(); int type = GLUtils.getType(bitmap); int format = GLUtils.getInternalFormat(bitmap); int error; int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, format, bitmap, type, 0); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); if (generateMipmap) { GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error, Integer.toString(error)); } bitmap.recycle(); return textures[0]; } catch(Exception e) { throw new RuntimeException(e); } } }; GameContext.glThread.sendEvent(runnable); return runnable.getResult(); }