aybe's picture

GL.GetAttachedShaders overload is bloated

Project:The Open Toolkit library
Category:bug report

At least one overload should provide count parameter as int.

Here is all the code needed just for this :

        /// <summary>
        /// Returns IDs of attached shaders.
        /// </summary>
        public unsafe int[] AttachedShaders
                // Get number of attached shaders
                int maxCount;
                GL.GetProgram(_id, ProgramParameter.AttachedShaders, out maxCount);
                // Get IDs of attached shaders
                IntPtr ptr = Marshal.AllocHGlobal(sizeof(int));
                void* pointer = ptr.ToPointer();
                int* count = (int*)pointer;
                int written;
                int[] shaders = new int[maxCount];
                GL.GetAttachedShaders(_id, maxCount, count, shaders);
                // Get the number of IDs written
                written = *count;
                return shaders;

Thread I opened first on forum : Using GL.GetAttachedShaders

Thanks !


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture


Version:1.0-2010-10-06» 1.1-dev
Status:open» fixed

You can now use:

int maxCount;
GL.GetProgram(id, ProgramParameter.AttachedShaders, out maxCount);
int count;
int[] shaders = new int[maxCount];
GL.GetAttachedShaders(id, shaders.Length, out count, shaders);

No need for unsafe code or unmanaged memory allocations.

the Fiddler's picture


Version:1.1-dev» 1.1-2014-01-02
Status:fixed» closed

Closing bugs fixed in OpenTK 1.1.

If this is still an issue please file a new bug report at https://github.com/opentk/opentk/issues