微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 OpenTK

如何解决使用 OpenTK

我有一个使用 OpenTK 1.0 的 Visual Studio 2019 用 C# 编写的 3D 图形 Xamarin 项目。 Xamarin 是 5.0.0.1905 版,OpenTK 是 4.0.30319 版。 该应用程序在某些 Android 设备上运行良好,但在调用 DrawArrays 方法并将纹理应用于表面时会在其他设备上崩溃。由于所有堆栈跟踪都引用了“libGLESv2_adreno”,我猜测受影响的设备都具有 Qualcomm Adreno GPU。

这是一个典型的堆栈跟踪:

signal 11 (SIGSEGV),code 1 (SEGV_MAPERR)

backtrace:
  #00  pc 000000000001dc18  /system/lib64/libc.so (memcpy+232)
  #00  pc 00000000001d0d64  /vendor/lib64/egl/libGLESv2_adreno.so (EsxVertexArrayObject::UpdateInternalVbos(EsxDrawDescriptor const*,unsigned int,EsxAttributeDesc const*)+1644)
  #00  pc 00000000003374f4  /vendor/lib64/egl/libGLESv2_adreno.so (A5xVertexArrayObject::CalcVfdregs(EsxDrawDescriptor const*,A5xVfdregs*,int)+892)
  #00  pc 000000000034ff54  /vendor/lib64/egl/libGLESv2_adreno.so (A5xContext::ValidateState(EsxDrawDescriptor const*)+1212)
  #00  pc 000000000033c820  /vendor/lib64/egl/libGLESv2_adreno.so (A5xContext::HwValidateGfxState(EsxDrawDescriptor const*)+16)
  #00  pc 0000000000115178  /vendor/lib64/egl/libGLESv2_adreno.so (EsxContext::ValidateGfxState(EsxDrawDescriptor const*)+1968)
  #00  pc 00000000000fd240  /vendor/lib64/egl/libGLESv2_adreno.so (EsxContext::DrawArraysInstanced(EsxPrimType,int,unsigned int)+416)
  #00  pc 0000000000014f08  <anonymous>

这里有两个似乎与问题有关的代码片段。它们是从相关项目中提取的,因此某些变量可能需要进一步说明(请告诉我)。

首先设置纹理:

using OpenTK.Graphics.ES31;
  
...

int[] textures = new int[1];

GL.GenTextures(1,textures);

GL.BindTexture(TextureTarget.Texture2D,textures[0]);

if (bitMap != null)
{
    //allocate memory on the graphics card for the texture.
    glutils.TexImage2D((int)All.Texture2D,bitMap,0);
    GL.GenerateMipmap(TextureTarget.Texture2D);
    GL.TexParameter(TextureTarget.Texture2D,TextureParameterName.TextureMagFilter,(int)All.Nearest);
    GL.TexParameter(TextureTarget.Texture2D,TextureParameterName.TextureMinFilter,(int)All.NearestMipmapLinear);
    GL.TexParameter(TextureTarget.Texture2D,TextureParameterName.TextureWrapS,(int)All.Repeat);
    GL.TexParameter(TextureTarget.Texture2D,TextureParameterName.TextureWrapT,(int)All.Repeat);
    b.Recycle();
}

GL.BindTexture(TextureTarget.Texture2D,0);

其次,绘制曲面:

worldGLView.vertices = vertexLists[bufferIndex].ToArray();
worldGLView.texture_coordinates = textureVertexLists[bufferIndex].ToArray();

unsafe
{
    fixed (Vector4* pvertices = worldGLView.vertices)
    {
        // Prepare the triangle coordinate data
        GL.VertexAttribPointer(worldGLView.tShaderProgram.mPositionHandle,Vector4.SizeInBytes / 4,VertexAttribPointerType.Float,false,new IntPtr(pvertices));
    }

    fixed (Vector2* ptexturecoordinates = worldGLView.texture_coordinates)
    {
        // Prepare the triangle texture data
        GL.VertexAttribPointer(worldGLView.tShaderProgram.mTextureCoordinatesHandle,Vector2.SizeInBytes / 4,new IntPtr(ptexturecoordinates));
    }
}

GL.DrawArrays(BeginMode.Triangles,worldGLView.vertices.Length);

任何人都可以建议可能导致问题的原因以及我如何解决它?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。