【问题标题】:OpenTK GenFramebuffers errorOpenTK GenFramebuffers 错误
【发布时间】:2012-07-01 10:34:38
【问题描述】:

我正在尝试使用 OpenTK 中的 GenFramebuffers 函数。在本机 OpenGL 中,此函数需要生成许多帧缓冲区名称和一个指向 int 的指针,这些名称将存储在其中。但是 OpenTK 变体需要多个名称来生成和单个 Int32 参数。

这是来自 OpenTK 的函数源代码:

    public static void GenFramebuffers(Int32 n, out Int32 framebuffers)
    {
        unsafe
        {
            fixed (Int32* framebuffers_ptr = &framebuffers)
            {
                Delegates.glGenFramebuffers((Int32)n, (UInt32*)framebuffers_ptr);
                framebuffers = *framebuffers_ptr;
            }
        }
    }

据我所知,如果将 1 以外的任何值指定为 n,它将覆盖内存。为了确保这一点,我实际上用 n=2 进行了尝试,它确实写了我作为 out 参数传递的 Int32 加上一个恰好在内存中的 Int32。

这不是OpenTK中唯一受影响的函数,所有的genXXX函数都是这样的。

我是疯了还是 OpenTK 严重损坏了?

【问题讨论】:

    标签: c# opengl opentk


    【解决方案1】:

    我认为这是内部功能。 OpenTK 在 GL 类中有这个函数来生成单帧缓冲区:

        public static int GenFramebuffer()
        {
            int id;
            GenFramebuffers(1, out id);
            return id;
        }
    

    对于数组类型参数,OpenTK 具有以下功能:

    void GenFramebuffers(Int32 n, [OutAttribute] Int32[] framebuffers)
    unsafe void GenFramebuffers(Int32 n, [OutAttribute] Int32* framebuffers)
    

    但我相信你也可以这样使用你提到的函数:

    int[] arr = new int[15];
    GenFramebuffers(10, out arr[5]); // will fill 10 starting with index 5
    

    【讨论】:

    • 如果它是内部的,它不应该是公开的,我不应该被允许调用它。
    • 它是一个公共 API,但正确使用它是您的责任。您可以在数组重载(对于多个值)、out 重载(对于单个返回值,您不想在其中分配 1 元素数组)和不安全指针重载(对于非 GC 数据分配有用)之间进行选择.)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 2011-04-10
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    相关资源
    最近更新 更多