glMapBufferRange返回Android中全部为零 [英] glMapBufferRange returning all zeros in Android

查看:1801
本文介绍了glMapBufferRange返回Android中全部为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从glMapBufferRange映射的一个缓冲器中读出

I am having trouble reading out from a buffer mapped with glMapBufferRange

如果我只是把一些数据缓冲区

If I simply put some data in a buffer

    // Create input VBO and vertex format
    int bufferLength = 5 * 4; //5 floats 4 bytes each
    FloatBuffer data = ByteBuffer.allocateDirect(bufferLength)
            .order(ByteOrder.nativeOrder()).asFloatBuffer();
    float[] floatData = { 1.0f, 4.0f, 9.0f, 16.0f, 25.0f };
    data.put(floatData).position(0);

生成一个数组缓冲区的GL和与数据填充

Generate a Array Buffer in GL and fill it with the data

    int[] vbo = new int[1];
    GLES30.glGenBuffers(1, vbo, 0);
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, vbo[0]);
    GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, bufferLength, data, GLES30.GL_STATIC_DRAW);
    MyGLRenderer.checkGlError(TAG + " glBufferData GL_ARRAY_BUFFER");

当我使用映射缓冲区 glMapBufferRange 和读取结果

When I map the buffer using glMapBufferRange and read the results

    Buffer mappedBuffer =  GLES30.glMapBufferRange(GLES30 .GL_ARRAY_BUFFER,
            0, bufferLength, GLES30.GL_MAP_READ_BIT);

    if (mappedBuffer!=null){
        FloatBuffer transformedBuffer = ((ByteBuffer) mappedBuffer).asFloatBuffer();
        MyGLRenderer.checkGlError(TAG + " glMapBufferRange");

        Log.d(TAG, String.format("pre-run input values = %f %f %f %f %f\n", transformedBuffer.get(),
                transformedBuffer.get(), transformedBuffer.get(), transformedBuffer.get(), transformedBuffer.get()));
        transformedBuffer.position(0);

    }
    GLES30.glUnmapBuffer(GLES30.GL_ARRAY_BUFFER);

在logcat中读取所有零

The logcat reads all zeros

D/TransformFeedback﹕ pre-run input values = 0.000000 0.000000 0.000000 0.000000 0.000000

不生成任何其他错误,我真的不知道要检查什么。我曾尝试 GLES30.glCopyBufferSubData(GLES30.GL_ARRAY_BUFFER,GLES30.GL_COPY_READ_BUFFER,0,0,BufferLength中); 和映射GL_COPY_READ_BUFFER,并得到了相同的结果。

No other errors are generated and I am not really sure what else to check. I have tried GLES30.glCopyBufferSubData(GLES30.GL_ARRAY_BUFFER, GLES30.GL_COPY_READ_BUFFER, 0, 0, bufferLength); and mapping GL_COPY_READ_BUFFER and gotten the same results.

我上支持OpenGL ES一台Nexus 6测试3.1所以这个功能应该是present。

I am testing on a Nexus 6 which supports OpenGL ES 3.1 so this functionality should be present.

问题建议去除GLFW的OPENGL_FORWARD_COMPAT暗示,可能会有类似的事情需要发生在MyGLSurfaceView?

This question suggests removing the OPENGL_FORWARD_COMPAT hint in glfw, could there be something similar that needs to happen in MyGLSurfaceView?

推荐答案

这看起来像一个字节序的问题,当你读回的数据。该数据将在本地字节顺序,而Java假定在默认情况下,在缓冲区的数据是大​​端。由于大多数架构是little endian的这些天,这就是你所需要的是相反的。

This looks like a byte order problem when you read back the data. The data will be in native byte order, while Java assumes by default that data in buffers is big endian. Since most architectures are little endian these days, that's the opposite of what you need.

要的方式,才能既为大和little endian架构工作纠正这一点,你可以做到以下几点:

To correct for this in a way that will work for both big and little endian architectures, you can do the following:

ByteBuffer byteBuf = (ByteBuffer)mappedBuffer;
byteBuf.order(ByteOrder.nativeOrder());
FloatBuffer floatBuf = byteBuf.asFloatBuffer();

然后,当您从 floatBuf 读,你应该得到正确的值。

Then when you read from floatBuf, you should get the correct values.

这篇关于glMapBufferRange返回Android中全部为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆