I’m sorry to bother you guys with questions that have already asked but I still can’t solve this problem.
I have this simple function that takes ages to complete:
void procFrame(JNIenv env, jint texIn, jint texOut, jint w, jint h) {
static cv::Mat m;
m.create(h, w, CV_8UC4);
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, m.data);
cv::Filter(m, m, CV_8U);
m *= 10;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texOut);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, m.data);
}
Someone suggested me to use pbos but I can’t figure out how to make them works with my project.
This is what I came up with:
static cv::Mat m;
bool initialized = false;
static int index = 0;
static int nextIndex = 0;
static int DATA_SIZE = 0;
void procFrame(JNIenv env, jint texIn, jint texOut, jint w, jint h) {
if (!initialized) {
m.create(w, h, CV_8UC4);
DATA_SIZE = w * h * 4;
glGenBuffers(2, pbo);
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo[0]);
glBufferData(GL_PIXEL_PACK_BUFFER, DATA_SIZE, 0, GL_STATIC_READ);
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo[1]);
glBufferData(GL_PIXEL_PACK_BUFFER, DATA_SIZE, 0, GL_STREAM_DRAW);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
initialized = true;
}
index = (index + 1) % 2;
nextIndex = (index + 1) % 2;
int64_t t = getTimeMs();
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo[index]);
glReadPixels(0, 0, w, h, GL_BGRA_EXT, GL_UNSIGNED_BYTE, 0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo[nextIndex]);
GLubyte* src = (GLubyte*)glMapBufferOES(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
if(src)
{
// TODO process
cv::Laplacian(m, m, CV_8U);
m *=10;
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
}
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D, texOut);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA_EXT, GL_UNSIGNED_BYTE, m.data);
}
Can anyone explain to me how to proceed and why?
Also I would love to have OpenGL ES books suggestions.
Thanks for your patience, guys