I am developing a camera app using OpenGL.
I found that GLES20.glReadPixels works fine but does not work with some devices.
It works smoothly on almost all devices, but only on the Galaxy S10 and Galaxy Note 10 models, glReadPixels returns 0.
And strange thing is that drawing on the gltexture works well. However, glReadPixels returns 0.
GLES20.glGetError() also returns 0.
The OpenGL context exists in the same class as the code below.
My code snippet :
val previewWidth = previewSize.width
val previewHeight = previewSize.height
val b = IntArray(previewWidth * previewHeight)
val bt = IntArray(previewWidth * previewHeight)
val bb = IntBuffer.wrap(b).apply { position(0) }
GLES20.glReadPixels(0, 0, previewWidth, previewHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, bb)
Log.d("Render", "GLES20.glGetError() : ${GLES20.glGetError()}")
for (i in 0 until previewHeight) {
for (j in 0 until previewWidth) {
val pix = b[i * previewWidth + j].toLong()
val pb = (pix shr 16) and 0xFF
val pr = (pix shl 16) and 0x00FF0000
val pix1 = (pix and 0xFF00FF00) + pb + pr
bt[(previewHeight - i - 1) * previewWidth + j] = pix1.toInt()
}
}
Does anyone know or have a solution to this problem?