Issue
I have a question, I want to use glMapBufferRange to read out data. The way I use it is the following:
bindBuffer(vboIdx);
void *ptr = glMapBufferRange(GL_ARRAY_BUFFER, 0, size, GL_MAP_READ_BIT);
int err = glGetError();
assert(ptr);
memcpy(dst, ptr, size);
glUnmapBuffer(GL_ARRAY_BUFFER);
unbindBuffer();
However, ptr seems to be NULL. As stated in the documentation here: https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glMapBufferRange.xhtml the function returns NULL if an error occured. Therefore, I checked for the error by using glGetError(). But the error I get is 0, which is the same as GL_NO_ERROR. So what am I missing, what am I doing wrong?
Thanks in advance!
Solution
Honestly, I haven't heard about the openGL context so far (just read about it), I started writing my code based on android's sensor graph sample project: https://github.com/android/ndk-samples/tree/master/sensor-graph. To answer your question, I haven't had a problem so far and I guess yes, but I'm not 100% sure. Before requesting a data read out I write data to the buffer:
if(dataSize == 0) {
return;
}
bindBuffer(vboIdx);
if(dataSize > vertexBufSize[vboIdx] - offset) {
glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STREAM_DRAW);
vertexBufSize[vboIdx] = dataSize;
}
void *ptr = glMapBufferRange(GL_ARRAY_BUFFER, offset, dataSize, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
int err = glGetError();
assert(ptr);
if(data != nullptr) {
memcpy(ptr, data, dataSize);
}
glUnmapBuffer(GL_ARRAY_BUFFER);
unbindBuffer();
This is where I call glBufferData()
Update: Java Side:
mView = (GLSurfaceView) frameLayout.findViewById(R.id.plot_view);
mView.setEGLContextClientVersion(3);
mView.setEGLConfigChooser(true);
if(LOG) Log.d(TAG, "onCreateView(): get ID: " + mView.getId());
isStreaming = true;
mView.setRenderer(new GLSurfaceView.Renderer() {
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
mLiveViewJNI.surfaceCreated();
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
mLiveViewJNI.surfaceChanged(width, height);
}
@Override
public void onDrawFrame(GL10 gl) {
mLiveViewJNI.drawFrame();
}
});
Update: @Matic Oblak You were right, the context was actually a problem. As long as I only touched the buffers via JNI within onSurfaceCreated, onSurfaceChanged or onDrawFrame everything was fine. But as soon as I tried to access them outside for instance via mLiveViewJNI.dummyCall I ran into that problem and everything returned 0 or NULL. Thanks :)!
Answered By - Grimfandango
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.