0

I am trying to draw a camera preview on Android via openGL. Preview texture is obtain as external EGL image through SurfaceTexture and then I draw it using a fairly simple shader:

#extension GL_OES_EGL_image_external : require
precision mediump float;
uniform samplerExternalOES sTexture;
varying vec2 texCoord;
    void main() {
    gl_FragColor = texture2D(sTexture,texCoord);
}

On nexus 5 it's working for all the preview images up to 1280x960. However for the biggest 2: 1920x1080 and 1600x1200 the screen is just blank. I set preview size in my camera obtained via camera.getSupportedPreviewSizes, so I am not trying to set anything which is unsupported by the camera.

    public  List<Camera.Size>  getSupportedResolutions()
    {
        List<Camera.Size> previewSizes = mCamera.getParameters().getSupportedPreviewSizes();
        List<Camera.Size> pictureSizes = mCamera.getParameters().getSupportedPictureSizes();

        pictureSizes.retainAll(previewSizes);

        return pictureSizes;
    }

 private void setResolution(int position)
    {
        List<Camera.Size> res = getSupportedResolutions();

        Camera.Parameters p =  mCamera.getParameters();
        p.setPictureSize(res.get(position).width, res.get(position).height);
        p.setPreviewSize(res.get(position).width, res.get(position).height);

        mCamera.setParameters(p);
    }

any suggestion what might go be wrong with those resolutions? maybe some kind of size limit in opengl?

  • 1
    There is a max texture size, which you can query: http://stackoverflow.com/questions/8573178/ . However, that's likely much larger than your camera images. I don't know if there's a separate limit for "external" textures. Do these larger resolutions work if you just send them directly to a TextureView (which uses SurfaceTexture internally) or a SurfaceView (which does not)? – fadden May 20 '15 at 15:47
  • I figured the problem. if preview size is larger than the size of my surfaceView I just set improper viewport. clamping it by (0, screenW) , (0, screenH) fixes the problem. There is no separate limit for external images, that was fully my fault – Sergey Solovyev May 20 '15 at 21:22
  • You should write that up as the answer -- http://stackoverflow.com/help/self-answer – fadden May 20 '15 at 21:30

1 Answers1

0

I figured the problem. if preview size is larger than the size of my surfaceView I just set improper viewport. clamping it by (0, screenW) , (0, screenH) fixes the problem. There is no separate limit for external images, that was fully my fault